package com.aoneposapp;

import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.regex.Pattern;

import org.apache.http.NameValuePair;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.BitmapFactory;
import android.net.ConnectivityManager;
import android.net.ParseException;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
import android.view.WindowManager;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.DigitalClock;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.TextView.OnEditorActionListener;
import android.widget.Toast;

import com.aoneposapp.utils.DatabaseForDemo;
import com.aoneposapp.utils.GetJSONListener;
import com.aoneposapp.utils.JSONforDemoData;
import com.aoneposapp.utils.JsonPostMethod;
import com.aoneposapp.utils.JsonPostWithAsnk;
import com.aoneposapp.utils.Parameters;
import com.aoneposapp.utils.ServerSyncClass;

public class LoginHomeActivity extends Activity {
	private EditText userName, passWord;
	private ImageView loginButton;
	private String uName = " ", pWord = " ", status = "a",status_first="w";
	Button filebutton;
//	String urlval = "";
	String name, cost, no, dp, vlu, pri, st, tax, vndrNo, vndrName, qty, price,
			catid;
	TextView tv1, tv2, tv3;
	ImageView imageView;
	public final Pattern EMAIL_ADDRESS_PATTERN = Pattern
			.compile("[a-zA-Z0-9+._%-+]{1,256}" + "@"
					+ "[a-zA-Z0-9][a-zA-Z0-9-]{0,64}" + "(" + "."
					+ "[a-zA-Z0-9][a-zA-Z0-9-]{0,25}" + ")+");
	RelativeLayout imageLayout, loginLayout, topView;
	String data = "      Retail Cash Register \n \n"
			+ "   AonePos Software and Database Version  4.3Jelly Bean \n"
			+ "   Production Version : 4.3 Jelly Bean   \n \n"
			+ "         Designed and Developed By \n"
			+ "                   AonePos \n \n"
			+ "   RCR 2012 20012-2013 AonePos \n \n"
			+ "   Model: Retail Cash Register Copyright 2012-2014 AonePos  \n \n";

	String data1 = " \n NTEP Ceritificate of Conformance # \n"
			+ "      View Cerificate: PDF  \n \n"
			+ "Operating System : Android 4.3 Jelly Bean \n" + "Tablet Name:"
			+ "Store ID :  01";
	public static ArrayList<NameValuePair> arr = new ArrayList<NameValuePair>();
	boolean isOpened = false;

	DatabaseForDemo sqlA1;
	SQLiteDatabase dbforloginlogoutWrite,dbforloginlogoutRead;
	
	@SuppressWarnings("deprecation")
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.login_home);
		System.gc();
		Parameters.menufinish=false;
		DigitalClock dc = (DigitalClock) findViewById(R.id.digitalClock1);
		imageLayout = (RelativeLayout) findViewById(R.id.imageLayout);
		loginLayout = (RelativeLayout) findViewById(R.id.loginlayout);
		topView = (RelativeLayout) findViewById(R.id.topview);
		/*ServerSyncClass synccall = new ServerSyncClass();
		Parameters.userid="hari";
		System.out.println("class object is created");
		try {
			synccall.generalMethod();
		} catch (ParseException e2) {
			// TODO Auto-generated catch block
			e2.printStackTrace();
		} catch (java.text.ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}*/
		
		sqlA1 = new DatabaseForDemo(LoginHomeActivity.this);
		dbforloginlogoutWrite = sqlA1.getWritableDatabase();
		dbforloginlogoutRead = sqlA1.getReadableDatabase();
		sqlA1.onUpgrade(dbforloginlogoutWrite, 1, 4);
		
		final View activityRootView = getWindow().getDecorView().findViewById(
				android.R.id.content);
		activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(
				new OnGlobalLayoutListener() {
					@Override
					public void onGlobalLayout() {

						int heightDiff = activityRootView.getRootView()
								.getHeight() - activityRootView.getHeight();
						if (heightDiff > 100) {
							Log.v("hari", "keybooasfdsdk");
							topView.setVisibility(View.GONE);
							isOpened = true;
						} else if (isOpened == true) {
							Log.v("hari", "ramaseetha");
							isOpened = false;
							topView.setVisibility(View.VISIBLE);
						}
					}
				});

		
		Log.e("open","sqlA1");
	
		String paymenttypevalis = "select "+DatabaseForDemo.PaymentProcessorName+" from "+DatabaseForDemo.PaymentProcessorPreferences;
		Cursor cursordedf = dbforloginlogoutRead.rawQuery(paymenttypevalis, null);
		startManagingCursor(cursordedf);
		if(cursordedf!=null){
			if(cursordedf.getCount()>0){
				if(cursordedf.moveToFirst()){
					do{
						if(cursordedf.isNull(cursordedf.getColumnIndex(DatabaseForDemo.PaymentProcessorName))){
							Parameters.paymentprocesstype = "Express Manual";
						}else{
							Parameters.paymentprocesstype = cursordedf.getString(cursordedf.getColumnIndex(DatabaseForDemo.PaymentProcessorName));
						}
					}while(cursordedf.moveToNext());
				}
			}
		}
//		cursordedf.close();
		Log.e("close","cursordedf");
		boolean isurlval = false;
	//	int countvalis = mCursor.getCount();
		String query = "select " + DatabaseForDemo.MISCEL_PAGEURL + " from "
				+ DatabaseForDemo.MISCELLANEOUS_TABLE;
		Cursor miscur = dbforloginlogoutRead.rawQuery(query, null);
		 startManagingCursor(miscur);
		if (miscur != null) {
			if (miscur.getCount() > 0) {
				if (miscur.moveToFirst()) {
					do {
						if (miscur
								.isNull(miscur
										.getColumnIndex(DatabaseForDemo.MISCEL_PAGEURL))) {
							isurlval = false;
						} else {
							String urlval = miscur
									.getString(miscur
											.getColumnIndex(DatabaseForDemo.MISCEL_PAGEURL));
							isurlval = true;
							Parameters.OriginalUrl = urlval;
							System.out.println("url val is:" + urlval);
						}
					} while (miscur.moveToNext());
				}
			}
		}
//		miscur.close();
		//Parameters.mfindServer_url = true;
		String selectQuery = "SELECT  * FROM "
				+ DatabaseForDemo.INVENTORY_TABLE;
		Cursor mCursor = dbforloginlogoutRead.rawQuery(selectQuery, null);
		startManagingCursor(mCursor);
		if (mCursor.getCount()>0 || isurlval == true) {
			
		}else{ 
			String atavffal="asdf";
		  JSONforDemoData client = new JSONforDemoData(LoginHomeActivity.this);
		       client.execute(atavffal);	    	
		System.out.println("method fghdghdg executed");
		
			/* harinath
				System.out.println("");
				DatabaseForDemo demofortax = 
				 dbtax = demofortax.getWritableDatabase();
				
				ContentValues values1 = new ContentValues();
				values1.put(DatabaseForDemo.TAX_NAME, "Tax1");
				values1.put(DatabaseForDemo.TAX_VALUE, "8.25");
				values1.put(DatabaseForDemo.CREATED_DATE, Parameters.currentTime());
				values1.put(DatabaseForDemo.MODIFIED_DATE, Parameters.currentTime());
				values1.put(DatabaseForDemo.UNIQUE_ID, Parameters.randomValue());
				values1.put(DatabaseForDemo.MODIFIED_IN, "Local");
				dbtax.insert(DatabaseForDemo.TAX_TABLE, null, values1);
				
				ContentValues values2 = new ContentValues();
				values2.put(DatabaseForDemo.TAX_NAME, "Tax2");
				values2.put(DatabaseForDemo.TAX_VALUE, "0");
				values2.put(DatabaseForDemo.CREATED_DATE, Parameters.currentTime());
				values2.put(DatabaseForDemo.MODIFIED_DATE, Parameters.currentTime());
				values2.put(DatabaseForDemo.UNIQUE_ID, Parameters.randomValue());
				values2.put(DatabaseForDemo.MODIFIED_IN, "Local");
				dbtax.insert(DatabaseForDemo.TAX_TABLE, null, values2);
				
				ContentValues values3 = new ContentValues();
				values3.put(DatabaseForDemo.TAX_NAME, "Tax3");
				values3.put(DatabaseForDemo.TAX_VALUE, "0");
				values3.put(DatabaseForDemo.CREATED_DATE, Parameters.currentTime());
				values3.put(DatabaseForDemo.MODIFIED_DATE, Parameters.currentTime());
				values3.put(DatabaseForDemo.UNIQUE_ID, Parameters.randomValue());
				values3.put(DatabaseForDemo.MODIFIED_IN, "Local");
				dbtax.insert(DatabaseForDemo.TAX_TABLE, null, values3);
				
				dbtax.close();
				demofortax.close();
				
				printerDemoData();
				orDatabase();
				orDatabaseCat();
				micellaneousTable();
				//Log.v("gfdkg", "super2");
				int p = 0;
				try {

					POIFSFileSystem myFileSystem = new POIFSFileSystem(
							getAssets().open("sampledata.xls"));
					Log.e(" before myFileSystem", "" + myFileSystem);
					HSSFWorkbook myWorkBook = new HSSFWorkbook(myFileSystem);
					Log.e(" before myWorkBook", "" + myWorkBook);
					HSSFSheet mySheet = myWorkBook.getSheetAt(0);
					Log.e(" before mySheet", "" + mySheet);

					Iterator<Row> rowIter = mySheet.rowIterator();
					Log.e(" before rowIter", "" + rowIter);

					while (rowIter.hasNext()) {
						HSSFRow myRow = (HSSFRow) rowIter.next();
						Log.e("  myRow", "" + myRow);
						Iterator<Cell> cellIter = myRow.cellIterator();
						Log.e("  cellIter", "" + cellIter);
						if (p <= 200) {
							p++;
							int i = 0;

							while (cellIter.hasNext()) {
								HSSFCell myCell = (HSSFCell) cellIter.next();
								Log.e("  myCell", "" + myCell);

								if (i == 0)
									name = "" + myCell;

								if (i == 1)
									no = "" + myCell;
								if (i == 2)
									dp = "" + myCell;
								if (i == 3)
									cost = "" + myCell;
								if (i == 4)
									st = "" + myCell;
								if (i == 5)
									vlu = "" + myCell;
								if (i == 6)
									price = "" + myCell;
								if (i == 7)
									vndrNo = "" + myCell;
								if (i == 8)
									vndrName = "" + myCell;
								if (i == 9)
									catid = "" + myCell;

								Log.w("FileUtils",
										"Cell Value: " + myCell.toString());

								i++;
							}
							String random = Parameters.randomValue();
							String now_date = Parameters.currentTime();

							ContentValues contentValues = new ContentValues();
							contentValues.put(
									DatabaseForDemo.INVENTORY_AVG_COST, cost);
							contentValues.put(
									DatabaseForDemo.INVENTORY_DEPARTMENT, dp);
							contentValues.put(DatabaseForDemo.INVENTORY_TAXONE,
									"Tax1");
							contentValues.put(
									DatabaseForDemo.INVENTORY_IN_STOCK, st);
							contentValues.put(
									DatabaseForDemo.INVENTORY_ITEM_NAME, name);
							contentValues.put(
									DatabaseForDemo.INVENTORY_ITEM_NO, no);
							contentValues.put(
									DatabaseForDemo.INVENTORY_PRICE_CHANGE,
									price);
							contentValues.put(
									DatabaseForDemo.INVENTORY_PRICE_TAX, (Double.parseDouble(price)+(Double.parseDouble(price)*8.25/100)));
							contentValues.put(
									DatabaseForDemo.INVENTORY_QUANTITY, "1");
							contentValues
									.put(DatabaseForDemo.INVENTORY_SECOND_DESCRIPTION,
											"description");
							contentValues
									.put(DatabaseForDemo.INVENTORY_TOTAL_TAX,
											(Double.parseDouble(price)*8.25/100));
							contentValues
									.put(DatabaseForDemo.UNIQUE_ID, random);
							contentValues.put(DatabaseForDemo.CREATED_DATE,
									now_date);
							contentValues.put(DatabaseForDemo.MODIFIED_DATE,
									now_date);
							contentValues.put(DatabaseForDemo.MODIFIED_IN,
									"Local");
							contentValues.put(
									DatabaseForDemo.INVENTORY_CATEGORY, catid);
							contentValues.put(DatabaseForDemo.INVENTORY_VENDOR,
									vndrNo);
							contentValues.put(DatabaseForDemo.INVENTORY_NOTES,
									"none");
							contentValues.put(DatabaseForDemo.CHECKED_VALUE,
									"true");
							sqliteDatabaseA1.insert(
									DatabaseForDemo.INVENTORY_TABLE, null,
									contentValues);
							contentValues.clear();
							ContentValues optional_info = new ContentValues();
							optional_info
									.put(DatabaseForDemo.UNIQUE_ID, random);
							optional_info.put(DatabaseForDemo.CREATED_DATE,
									now_date);
							optional_info.put(DatabaseForDemo.MODIFIED_DATE,
									now_date);
							optional_info.put(DatabaseForDemo.MODIFIED_IN,
									"Local");
							optional_info.put(DatabaseForDemo.BONUS_POINTS, "");
							optional_info.put(DatabaseForDemo.BARCODES, "");
							optional_info.put(DatabaseForDemo.LOCATION, "");
							optional_info.put(DatabaseForDemo.UNIT_SIZE, "");
							optional_info.put(DatabaseForDemo.UNIT_TYPE, "");
							optional_info.put(
									DatabaseForDemo.COMMISSION_OPTIONAL_INFO,
									"");
							optional_info.put(
									DatabaseForDemo.INVENTORY_ALLOW_BUYBACK,
									"no");
							optional_info.put(
									DatabaseForDemo.INVENTORY_PROMPT_PRICE,
									"no");
							optional_info.put(
									DatabaseForDemo.INVENTORY_FOODSTAMPABLE,
									"no");
							optional_info.put(
									DatabaseForDemo.INVENTORY_PRINT_ON_RECEIPT,
									"no");
							optional_info.put(
									DatabaseForDemo.INVENTORY_COUNT_THIS_ITEM,
									"no");
							optional_info.put(
									DatabaseForDemo.INVENTORY_MODIFIER_ITEM,
									"no");
							optional_info.put(
									DatabaseForDemo.INVENTORY_ITEM_NO, no);
							sqliteDatabaseA1.insert(
									DatabaseForDemo.OPTIONAL_INFO_TABLE, null,
									optional_info);

						}
					}

				} catch (Exception ex) {
				}
				harinath
		*/
			}
		//	} else {

			//}
		//}
//		mCursor.close();
//		dbforloginlogoutRead.close();
		//sqlA1.close();
		Log.e("Close","sqlA1");
		loginButton = (ImageView) findViewById(R.id.imageButton);
		filebutton = (Button) findViewById(R.id.filebutton);
		userName = (EditText) findViewById(R.id.userName);
		passWord = (EditText) findViewById(R.id.passWord);
		passWord.setOnEditorActionListener(new OnEditorActionListener() {
			@Override
			public boolean onEditorAction(TextView v, int actionId,
					KeyEvent event) {
				if (actionId == EditorInfo.IME_ACTION_DONE) {
					loginMainMethod();
				}
				return false;
			}
		});
		tv1 = (TextView) findViewById(R.id.textView1);
		tv2 = (TextView) findViewById(R.id.textView2);
		tv3 = (TextView) findViewById(R.id.textView3);
		imageView = (ImageView) findViewById(R.id.companylogo);
		File image = new File("/mnt/sdcard/harinath/hari.jpg");
		if (image.exists()) {

			imageView.setImageBitmap(BitmapFactory.decodeFile(image
					.getAbsolutePath()));
		}

		loginButton.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				loginMainMethod();
			}

		});

		filebutton.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				final AlertDialog alertDialog2 = new AlertDialog.Builder(
						LoginHomeActivity.this,
						android.R.style.Theme_Translucent_NoTitleBar).create();
				LayoutInflater mInflater1 = LayoutInflater
						.from(LoginHomeActivity.this);
				View layout1 = mInflater1.inflate(R.layout.options_popup, null);
				final ImageView nameR = (ImageView) layout1
						.findViewById(R.id.imageView1);
				final ImageView emailR = (ImageView) layout1
						.findViewById(R.id.imageView2);
				final ImageView phoneR = (ImageView) layout1
						.findViewById(R.id.imageView3);

				nameR.setOnClickListener(new OnClickListener() {

					@Override		
					public void onClick(View arg0) {
						// TODO Auto-generated method stub
						nameR.setBackgroundResource(R.drawable.registerbuttonpressed);
						alertDialog2.dismiss();
						final AlertDialog alertDialog2 = new AlertDialog.Builder(
								LoginHomeActivity.this).create();
						LayoutInflater mInflater1 = LayoutInflater
								.from(LoginHomeActivity.this);
						View layout1 = mInflater1.inflate(
								R.layout.register_xml, null);
						Button accept = (Button) layout1
								.findViewById(R.id.button1);
						Button decline = (Button) layout1
								.findViewById(R.id.button2);
						final EditText nameR = (EditText) layout1
								.findViewById(R.id.nameR);
						final EditText emailR = (EditText) layout1
								.findViewById(R.id.emailR);
						final EditText phoneR = (EditText) layout1
								.findViewById(R.id.phoneR);
						final EditText companyR = (EditText) layout1
								.findViewById(R.id.companyR);
						// WebView licence=(WebView)
						// layout1.findViewById(R.id.licence);

						// licence.loadUrl("file:///android_asset/register.html");

						accept.setOnClickListener(new OnClickListener() {

							@Override
							public void onClick(View arg0) {
								// TODO Auto-generated method stub

								String name = nameR.getText().toString().trim();
								String email = emailR.getText().toString()
										.trim();
								String phone = phoneR.getText().toString()
										.trim();
								String company = companyR.getText().toString()
										.trim();
								if (name.length() > 3) {
									if (checkEmail(email)) {
										if (company.length() > 3) {
											String url = "http://www.aonepos.com/customer-register.php";
											JsonPostWithAsnk client1 = new JsonPostWithAsnk(
													LoginHomeActivity.this, l,
													name, email, phone, company);
											client1.execute(url);

											alertDialog2.dismiss();
										} else {
											Toast.makeText(
													LoginHomeActivity.this,
													"Enter Full Company Name",
													Toast.LENGTH_SHORT).show();
										}
									} else {
										Toast.makeText(LoginHomeActivity.this,
												"Invalid Email Addresss",
												Toast.LENGTH_SHORT).show();
									}
								} else {
									Toast.makeText(getApplicationContext(),
											"Enter Name above 4 Characters",
											2000).show();
								}

							}
						});
						decline.setOnClickListener(new OnClickListener() {

							@Override
							public void onClick(View arg0) {
								// TODO Auto-generated method stub
								alertDialog2.dismiss();
							}
						});
						alertDialog2.setView(layout1);
						alertDialog2.getWindow().setSoftInputMode(
								WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
						alertDialog2.show();

					}
				});
				emailR.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View arg0) {
						// TODO Auto-generated method stub
						emailR.setBackgroundResource(R.drawable.aboutbuttonpressed);
						alertDialog2.dismiss();
						final AlertDialog alertDialog1 = new AlertDialog.Builder(
								LoginHomeActivity.this).create();
						LayoutInflater mInflater = LayoutInflater
								.from(LoginHomeActivity.this);
						View layout = mInflater
								.inflate(R.layout.about_us, null);
						Button ok = (Button) layout.findViewById(R.id.okkk);
						TextView viewlicense = (TextView) layout
								.findViewById(R.id.viewlicense);
						TextView topnormaltext = (TextView) layout
								.findViewById(R.id.topnormaltext);
						TextView Buttomtext = (TextView) layout
								.findViewById(R.id.Buttomtext);
						topnormaltext.setText(data);
						Buttomtext.setText(data1);
						viewlicense.setOnClickListener(new OnClickListener() {

							@Override
							public void onClick(View arg0) {
								// TODO Auto-generated method stub
								final AlertDialog alertDialog2 = new AlertDialog.Builder(
										LoginHomeActivity.this).create();
								LayoutInflater mInflater1 = LayoutInflater
										.from(LoginHomeActivity.this);
								View layout1 = mInflater1.inflate(
										R.layout.licence_agreement, null);
								Button accept = (Button) layout1
										.findViewById(R.id.accept);
								Button decline = (Button) layout1
										.findViewById(R.id.decline);
								WebView licence = (WebView) layout1
										.findViewById(R.id.licence);

								licence.loadUrl("file:///android_asset/register.html");

								accept.setOnClickListener(new OnClickListener() {

									@Override
									public void onClick(View arg0) {
										// TODO Auto-generated method stub
										alertDialog2.dismiss();
									}
								});
								decline.setOnClickListener(new OnClickListener() {

									@Override
									public void onClick(View arg0) {
										// TODO Auto-generated method stub
										alertDialog2.dismiss();
									}
								});
								alertDialog2.setView(layout1);
								alertDialog2.show();
							}
						});
						ok.setOnClickListener(new OnClickListener() {

							@Override
							public void onClick(View arg0) {
								// TODO Auto-generated method stub
								alertDialog1.dismiss();
							}
						});
						alertDialog1.setView(layout);
						alertDialog1.show();
					}
				});
				phoneR.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View arg0) {
						// TODO Auto-generated method stub
						alertDialog2.dismiss();
						finish();

					}
				});
				alertDialog2.setView(layout1);
				alertDialog2.show();
				// filemenu.setVisibility(View.VISIBLE);
			}
		});
	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		imageView = (ImageView) findViewById(R.id.companylogo);
		File image = new File("/mnt/sdcard/harinath/hari.jpg");
		if (image.exists()) {
			imageView.setImageBitmap(BitmapFactory.decodeFile(image
					.getAbsolutePath()));
		}
		Parameters.menufinish=false;
		sqlA1 = new DatabaseForDemo(LoginHomeActivity.this);
		dbforloginlogoutWrite = sqlA1.getWritableDatabase();
		dbforloginlogoutRead = sqlA1.getReadableDatabase();
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.login_home, menu);
		return true;
	}

	GetJSONListener l = new GetJSONListener() {

		@Override
		public void onRemoteCallComplete(JSONObject jsonFromNet) {
			// TODO Auto-generated method stub
			// showDatafromJSONObject(jsonFromNet);
			if(jsonFromNet.length()>2){
			Log.v("josn", "" + jsonFromNet);
			toastForRegister(jsonFromNet);
			}
			// if(jsonFromNet!=null) jsonParseFormServer(jsonFromNet);

		}

		private void toastForRegister(JSONObject jsonFromNet) {
			// TODO Auto-generated method stub
if(jsonFromNet!=null&&jsonFromNet.length()>2){
			try {
				JSONObject job = jsonFromNet.getJSONObject("response");
				String msg = job.getString("status");
				Toast.makeText(getApplicationContext(), "" + msg,
						Toast.LENGTH_LONG).show();
			} catch (JSONException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		}
		private void jsonParseFormServer(JSONObject jsonFromNet) {
			// TODO Auto-generated method stub
			if(jsonFromNet!=null&&jsonFromNet.length()>2){ 
			try {
				JSONArray deletequeries = jsonFromNet
						.getJSONArray("delete-queries");
				for (int i = 0; i < deletequeries.length(); i++) {
					String dQueries = deletequeries.getString(i);
					Log.v("DQ", dQueries);
					
					Log.v("open", "sqlA1");
//					 sqliteDatabaseB1 = dbforloginlogoutWrite.
					dbforloginlogoutWrite.execSQL(dQueries);

					Toast.makeText(LoginHomeActivity.this, "deleted", 1000)
							.show();
//					sqliteDatabaseB1.close();
					//sqlA1.close();
					Log.e("close", "sqlA1");
				}
				JSONArray insertqueries = jsonFromNet
						.getJSONArray("insert-queries");
				for (int i = 0; i < insertqueries.length(); i++) {
					String iQueries = insertqueries.getString(i);
					Log.v("DQ", iQueries);
					
					Log.e("open","sqlA1");
//					 sqliteDatabaseC1 = dbforloginlogoutWrite.
					 dbforloginlogoutWrite.execSQL(iQueries);

					Toast.makeText(LoginHomeActivity.this, "inserted", 1000)
							.show();
//					sqliteDatabaseC1.close();
					//sqlA1.close();
					Log.e("close","sqlA1");
				}
				JSONObject response = jsonFromNet.getJSONObject("response");
				String severtime = response.getString("server-time");
				String timeinSeconds = response
						.getString("time-difference-in-seconds");
				Log.v("DQ" + severtime, timeinSeconds);
				// // String severtime=response.getString("server-time");
				// String severtime=response.getString("server-time");

			} catch (JSONException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}else{
//			Toast.makeText(EmployeeActivity.this, "Server Error", 1000).show();
			Log.v("errorr", "server");
		}
		}
	};

	@Override
	public void onBackPressed() {

	};

	private boolean checkEmail(String mail) {
		return EMAIL_ADDRESS_PATTERN.matcher(mail).matches();
	}

	private void orDatabase() {
		String cat_id = "", dp_dp = "", dp_id = "", food = "";
		
		Log.v("open", "sqlA1");
//		 sqliteDatabaseD1 = dbforloginlogoutWrite.
		Log.v("gfdkg", "super");

		Log.v("gfdkg", "super1");
		String selectQuery = "SELECT  * FROM "
				+ DatabaseForDemo.INVENTORY_TABLE;
		Cursor mCursor = dbforloginlogoutWrite.rawQuery(selectQuery, null);
		startManagingCursor(mCursor);
		//Parameters.mfindServer_url = true;
		if (mCursor != null) {
			Log.v("gfdkg", "super333");
			String server_Url = "nnn";
			if (mCursor.getCount() < 10) {
				Log.v("gfdkg", "super2");
				int p = 0;
				try {

					POIFSFileSystem myFileSystem = new POIFSFileSystem(
							getAssets().open("department.xls"));
					HSSFWorkbook myWorkBook = new HSSFWorkbook(myFileSystem);
					HSSFSheet mySheet = myWorkBook.getSheetAt(0);
					Iterator<Row> rowIter = mySheet.rowIterator();
					while (rowIter.hasNext()) {
						HSSFRow myRow = (HSSFRow) rowIter.next();
						Iterator<Cell> cellIter = myRow.cellIterator();
						if (p <= 13) {
							p++;
							int i = 0;

							while (cellIter.hasNext()) {
								HSSFCell myCell = (HSSFCell) cellIter.next();
								Log.e("  myCell", "" + myCell);
								if (i == 0)
									cat_id = "" + myCell;
								if (i == 1)
									dp_id = "" + myCell;
								if (i == 2)
									dp_dp = "" + myCell;
								if (i == 3)
									food = "" + myCell;

								i++;
							}
							String random = Parameters.randomValue();
							String now_date = Parameters.currentTime();

							ContentValues contentValues = new ContentValues();

							contentValues.put(DatabaseForDemo.UNIQUE_ID,
									Parameters.randomValue());
							contentValues.put(DatabaseForDemo.CREATED_DATE,
									Parameters.currentTime());
							contentValues.put(DatabaseForDemo.MODIFIED_DATE,
									Parameters.currentTime());
							contentValues.put(DatabaseForDemo.MODIFIED_IN,
									"Local");
							contentValues.put(DatabaseForDemo.DepartmentID,
									dp_id);
							contentValues.put(DatabaseForDemo.DepartmentDesp,
									dp_dp);
							contentValues.put(
									DatabaseForDemo.CategoryForDepartment,
									cat_id);

							contentValues.put(
									DatabaseForDemo.FoodstampableForDept, "no");
							contentValues.put(DatabaseForDemo.TaxValForDept,
									"");
							contentValues.put(DatabaseForDemo.CHECKED_VALUE,
									"true");
							dbforloginlogoutWrite.insert(
									DatabaseForDemo.DEPARTMENT_TABLE, null,
									contentValues);
						}
					}

				} catch (Exception ex) {
				}

			} else {

			}
		}
//		mCursor.close();
//		sqliteDatabaseD1.close();
		//sqlA1.close();
		Log.e("close", "sqlA1");
	}

	private void orDatabaseCat() {
		String cat_id = "", cat_cat = "";
		
//		 sqliteDatabaseE1 = dbforloginlogoutWrite.
		Log.v("open", "sqlDE1");

		Log.v("gfdkg", "super1");
		String selectQuery = "SELECT  * FROM "
				+ DatabaseForDemo.INVENTORY_TABLE;
		Cursor mCursor = dbforloginlogoutWrite.rawQuery(selectQuery, null);
		startManagingCursor(mCursor);
	//	Parameters.mfindServer_url = true;
		if (mCursor != null) {
			Log.v("gfdkg", "super333");
			if (mCursor.getCount() < 10) {
				Log.v("gfdkg", "super2");
				int p = 0;
				try {

					POIFSFileSystem myFileSystem = new POIFSFileSystem(
							getAssets().open("categoryaaa.xls"));
					Log.e(" before myFileSystem", "" + myFileSystem);
					// Create a workbookusing the File System
					HSSFWorkbook myWorkBook = new HSSFWorkbook(myFileSystem);
					Log.e(" before myWorkBook", "" + myWorkBook);
					HSSFSheet mySheet = myWorkBook.getSheetAt(0);
					Iterator<Row> rowIter = mySheet.rowIterator();
					while (rowIter.hasNext()) {
						HSSFRow myRow = (HSSFRow) rowIter.next();
						Iterator<Cell> cellIter = myRow.cellIterator();
						if (p <= 10) {
							p++;
							int i = 0;

							while (cellIter.hasNext()) {
								HSSFCell myCell = (HSSFCell) cellIter.next();
								Log.e("  myCell", "" + myCell);
								if (i == 0)
									cat_id = "" + myCell;
								if (i == 1)
									cat_cat = "" + myCell;
								i++;
							}

							ContentValues contentValues = new ContentValues();
							contentValues.put(DatabaseForDemo.UNIQUE_ID,
									Parameters.randomValue());
							contentValues.put(DatabaseForDemo.CREATED_DATE,
									Parameters.currentTime());
							contentValues.put(DatabaseForDemo.MODIFIED_DATE,
									Parameters.currentTime());
							contentValues.put(DatabaseForDemo.MODIFIED_IN,
									"Local");
							contentValues.put(DatabaseForDemo.CategoryId,
									cat_id);
							contentValues.put(DatabaseForDemo.CategoryDesp,
									cat_cat);
							dbforloginlogoutWrite.insert(
									DatabaseForDemo.CATEGORY_TABLE, null,
									contentValues);

						}
					}

				} catch (Exception ex) {
				}

			} else {

			}
		}
//		mCursor.close();
//		sqliteDatabaseE1.close();
		//sqlA1.close();
		Log.e("close","sqlA1");
	}

	public boolean isConnectingToInternet() {

		ConnectivityManager manager = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
		try{
				// For 3G check
				Log.v("error","conection");
			//	boolean is3g = manager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE)
				//		.isConnectedOrConnecting();
				// For WiFi Check
				Log.v("error","conection");
				boolean isWifi = manager.getNetworkInfo(ConnectivityManager.TYPE_WIFI)
						.isConnectedOrConnecting();
				Log.v("error","conection");
				// Toast.makeText(getBaseContext(), is3g + " net " + isWifi,
				// 6000).show();

				if (!isWifi) {

					return false;
				} else {
					return true;
				}
		}catch(Exception e){
			System.out.println(e);
			return true;
		}
	}

	void loginFunction() {
		
		boolean bool = true;
		//Parameters.sessionidforloginlogout = Parameters.randomValue();
		Parameters.logintime = Parameters.currentTime();
		uName = userName.getText().toString().trim();
		pWord = passWord.getText().toString().trim();
		Parameters.sessionidforloginlogout ="";
		
		if(uName.length()==0 || pWord.length()==0){
			Toast.makeText(getApplicationContext(),
					"Enter Username and password", 1000).show();
			return;
		}
		
		if (Parameters.OriginalUrl.equals("")) {
			System.out.println("there is no server url val");
			if (uName != null || pWord != null) {
				
				
				Log.v("open", "sqlA1");
				Cursor cursorlogin = dbforloginlogoutRead.rawQuery(
						"select * from " + DatabaseForDemo.ADMIN_TABLE+" where "+DatabaseForDemo.USERID+"='"+uName+"' and "
				+DatabaseForDemo.PASSWORD+"='"+Parameters.MD5(pWord)+"';", null);
				startManagingCursor(cursorlogin);
				if (cursorlogin.getCount() > 0) {
					Intent intent = new Intent(LoginHomeActivity.this,
							MenuActivity.class);
					startActivity(intent);
//					cursorlogin.close();
					Parameters.loggedinusertype = "admin";
					Parameters.usertype="admin";
					Parameters.userid = uName;
					Parameters.usertypeloginvalue = uName;
					adminPermissions(true);
					insertLoginTime();
					permissions();
				} else {
//					cursorlogin.close();
					Cursor cursoremp = dbforloginlogoutRead.rawQuery(
							"select * from " + DatabaseForDemo.EMPLOYEE_TABLE+" where "+DatabaseForDemo.EMPLOYEE_EMPLOYEE_ID+"='"+uName+"' and "
									+DatabaseForDemo.EMPLOYEE_PASSWORD+"='"+Parameters.MD5(pWord)+"';",
							null);
					startManagingCursor(cursoremp);
					if (cursoremp.getCount() > 0) {
						Intent intent = new Intent(LoginHomeActivity.this,
								MenuActivity.class);
						startActivity(intent);
						permissions();
						insertLoginTime();
						Parameters.loggedinusertype = "employee";
						Parameters.usertype="employee";
						Parameters.userid = uName;
						Parameters.usertypeloginvalue = uName;
						setEmployeePermissions();
						
					}else{
						if (uName.equals("01") && pWord.equals("admin")) {
							Parameters.loggedinusertype = "admin";
							Parameters.usertype="admin";
							Parameters.userid = uName;
							Parameters.usertypeloginvalue = uName;
							adminPermissions(true);
							insertLoginTime();
							permissions();
							Intent intent = new Intent(LoginHomeActivity.this,
									MenuActivity.class);
							startActivity(intent);
							
						} else {
							Toast.makeText(getApplicationContext(),
									"Enter correct Username and password", 1000).show();
						}
					}
//					cursoremp.close();
					
				}
				
				//sqlA1.close();
				Log.e("close","sqlA1");
				
			} else {
				Toast.makeText(getApplicationContext(),
						"Enter correct Username and password", 1000).show();
			}
		} else {
			System.out.println("server url val"+Parameters.OriginalUrl);
			
			if (Parameters.isNetworkAvailable(LoginHomeActivity.this)) {
				
				final JsonPostMethod value = new JsonPostMethod();
				new Thread(new Runnable() {
					@Override
					public void run() {
						String response = value.postmethodforlogin(uName,
								Parameters.MD5(pWord),
								Parameters.randomValue(),
								Parameters.currentTime());
						System.out.println("response val is: " + response);
						String servertime = "";
						if(response!=null&&response.length()>2){ 
						try {
							JSONObject jsonObj = new JSONObject(response);
							JSONObject responseobj = jsonObj
									.getJSONObject("response");
							servertime = responseobj.getString("server-time");
							status_first = jsonObj.getString("server-user-exists");
							status = jsonObj.getString("login-status");
							if(status_first.equals("true")){
							if(status.equals("true")){
							Parameters.sessionidforloginlogout = jsonObj.getString("sessionid");
							Parameters.loggedinusertype = jsonObj.getString("user-type");
							Parameters.usertype=jsonObj.getString("user-type");
							}
							}
							System.out.println("response value is:"
									+ jsonObj.toString(4));
							System.out.println("response value is:" + status);

						} catch (JSONException e) {
							// TODO Auto-generated catch block
							System.out.println("servertime is:harinath" + servertime);
							e.printStackTrace();
						}
						
						String select = "select *from "
								+ DatabaseForDemo.MISCELLANEOUS_TABLE;
						
						Log.v("open", "sqlA1");
//						 dbF1 = dbforloginlogoutWrite.
						Cursor cursor = dbforloginlogoutWrite.rawQuery(select, null);
						startManagingCursor(cursor);
						if (cursor.getCount() > 0) {
							dbforloginlogoutWrite.execSQL("update "
									+ DatabaseForDemo.MISCELLANEOUS_TABLE
									+ " set "
									+ DatabaseForDemo.MISCEL_SERVER_UPDATE_LOCAL
									+ "=\"" + servertime + "\"");
							
						} else {
							
							ContentValues contentValues1 = new ContentValues();
							contentValues1.put(DatabaseForDemo.MISCEL_STORE,
									"store1");
							contentValues1.put(DatabaseForDemo.MISCEL_PAGEURL,
									Parameters.OriginalUrl);
							contentValues1.put(
									DatabaseForDemo.MISCEL_UPDATE_LOCAL,
									Parameters.currentTime());
							contentValues1.put(
									DatabaseForDemo.MISCEL_SERVER_UPDATE_LOCAL,
									Parameters.currentTime());
							dbforloginlogoutWrite.insert(DatabaseForDemo.MISCELLANEOUS_TABLE,
									null, contentValues1);

						}
//						cursor.close();
						//sqlA1.close();
//						dbF1.close();
						Log.e("close","dbF1");
						}else{
							Log.v("errorr", "server");
							Message msgObj = handler
									.obtainMessage();
							Bundle b = new Bundle();
							b.putString("message", "bhdfgh");
							msgObj.setData(b);
							handler.sendMessage(msgObj);
						}
					}
					private final Handler handler = new Handler() {

						@Override
						public void handleMessage(Message msg) {

									Toast.makeText(getApplicationContext(),
											"Response Error", 1000).show();
						}
					};
				}).start();
				try {
					Thread.sleep(2000);
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				if(status_first.equals("true")){
					System.out.println("status_first true");
				if (status.equals("true")) {
					System.out.println("status true");
					insertLoginTime();
					if(Parameters.usertype.equals("admin")){
						Parameters.userid = uName;
						Parameters.usertypeloginvalue = uName;
						adminPermissions(true);
						permissions();
						Intent intent = new Intent(LoginHomeActivity.this,
								MenuActivity.class);
						startActivity(intent);
						
					}else{
						Parameters.userid = uName;
						Parameters.usertypeloginvalue = uName;
						setEmployeePermissions();
						permissions();
						Intent intent = new Intent(LoginHomeActivity.this,
								MenuActivity.class);
						startActivity(intent);
					}
					
				} else {
					Toast.makeText(getApplicationContext(),
							"Enter correct Username and password", 1000).show();
				}
				}else {
					
					Log.v("open", "sqlA1");
					System.out.println("status_first flase");
					if (uName != null || pWord != null) {
						Log.v("1","1");
						Cursor cursorlogin = dbforloginlogoutRead.rawQuery(
								"select * from " + DatabaseForDemo.ADMIN_TABLE+" where "+DatabaseForDemo.USERID+"='"+uName+"' and "
						+DatabaseForDemo.PASSWORD+"='"+Parameters.MD5(pWord)+"';", null);
						startManagingCursor(cursorlogin);
						if (cursorlogin.getCount() > 0) {
							Intent intent = new Intent(LoginHomeActivity.this,
									MenuActivity.class);
							startActivity(intent);
							permissions();
//							cursorlogin.close();
							Parameters.loggedinusertype = "admin";
							Parameters.usertype="admin";
							Parameters.userid = uName;
							Parameters.usertypeloginvalue = uName;
							adminPermissions(true);
							insertLoginTime();
							permissions();
						} else {
							Log.v("3431","4");
//							cursorlogin.close();
							Cursor cursoremp = dbforloginlogoutRead.rawQuery(
									"select * from " + DatabaseForDemo.EMPLOYEE_TABLE+" where "+DatabaseForDemo.EMPLOYEE_EMPLOYEE_ID+"='"+uName+"' and "
											+DatabaseForDemo.EMPLOYEE_PASSWORD+"='"+Parameters.MD5(pWord)+"';",
									null);
							startManagingCursor(cursoremp);
							if (cursoremp.getCount() > 0) {
								Intent intent = new Intent(LoginHomeActivity.this,
										MenuActivity.class);
								startActivity(intent);
								permissions();
//								cursorlogin.close();
								insertLoginTime();
								Parameters.loggedinusertype = "employee";
								Parameters.usertype="employee";
								Parameters.userid = uName;
								Parameters.usertypeloginvalue = uName;
								setEmployeePermissions();
								
							}else{
								Log.v("133","133");
								Cursor cursorlogin01 = dbforloginlogoutRead.rawQuery(
										"select * from " + DatabaseForDemo.ADMIN_TABLE, null);
								startManagingCursor(cursorlogin01);
								if (cursorlogin01.getCount() > 0) {
									Toast.makeText(getApplicationContext(),
											"Enter correct Username and password", 1000).show();
								}else{
								if (uName.equals("01") && pWord.equals("admin")) {
									Parameters.loggedinusertype = "admin";
									Parameters.usertype="admin";
									Parameters.userid = uName;
									Parameters.usertypeloginvalue = uName;
									adminPermissions(true);
									insertLoginTime();
									permissions();
									Log.v("1vcb","1vcb");
									Intent intent = new Intent(LoginHomeActivity.this,
											MenuActivity.class);
									startActivity(intent);
									Log.v("1zzz","zzz1");
								} else {
									Toast.makeText(getApplicationContext(),
											"Enter correct Username and password", 1000).show();
								}
								}
							}
//							cursoremp.close();
							
						}
						
						
						
					} else {
						Toast.makeText(getApplicationContext(),
								"Enter correct Username and password", 1000).show();
					}
				
					//sqlA1.close();
					Log.e("close","sqlA1");
				}
			}else{

				System.out.println("There is no net connection");
				if (uName != null || pWord != null) {
					
					
					Log.v("open", "sqlA1");
					Cursor cursorlogin = dbforloginlogoutRead.rawQuery(
							"select * from " + DatabaseForDemo.ADMIN_TABLE+" where "+DatabaseForDemo.USERID+"='"+uName+"' and "
					+DatabaseForDemo.PASSWORD+"='"+Parameters.MD5(pWord)+"';", null);
					startManagingCursor(cursorlogin);
					if (cursorlogin.getCount() > 0) {
						Intent intent = new Intent(LoginHomeActivity.this,
								MenuActivity.class);
						startActivity(intent);
						saveinpendingQry();
						permissions();
//						cursorlogin.close();
						Parameters.loggedinusertype = "admin";
						Parameters.usertype="admin";
						Parameters.userid = uName;
						Parameters.usertypeloginvalue = uName;
						adminPermissions(true);
						insertLoginTime();
						permissions();
					} else {
//						cursorlogin.close();
						Cursor cursoremp = dbforloginlogoutRead.rawQuery(
								"select * from " + DatabaseForDemo.EMPLOYEE_TABLE+" where "+DatabaseForDemo.EMPLOYEE_EMPLOYEE_ID+"='"+uName+"' and "
										+DatabaseForDemo.EMPLOYEE_PASSWORD+"='"+Parameters.MD5(pWord)+"';",
								null);
						startManagingCursor(cursoremp);
						if (cursoremp.getCount() > 0) {
							Intent intent = new Intent(LoginHomeActivity.this,
									MenuActivity.class);
							startActivity(intent);
							saveinpendingQry();
							permissions();
//							cursorlogin.close();
							insertLoginTime();
							Parameters.loggedinusertype = "employee";
							Parameters.usertype="employee";
							Parameters.userid = uName;
							Parameters.usertypeloginvalue = uName;
							setEmployeePermissions();
							
						}else{
						
							Cursor cursorlogin01 = dbforloginlogoutRead.rawQuery(
									"select * from " + DatabaseForDemo.ADMIN_TABLE, null);
							startManagingCursor(cursorlogin01);
							if (cursorlogin01.getCount() > 0) {
								Toast.makeText(getApplicationContext(),
										"Enter correct Username and password", 1000).show();
							}else{
							if (uName.equals("01") && pWord.equals("admin")) {
								Parameters.loggedinusertype = "admin";
								Parameters.usertype="admin";
								Parameters.userid = uName;
								Parameters.usertypeloginvalue = uName;
								adminPermissions(true);
								insertLoginTime();
								permissions();
								Intent intent = new Intent(LoginHomeActivity.this,
										MenuActivity.class);
								startActivity(intent);
								saveinpendingQry();
							} else {
								Toast.makeText(getApplicationContext(),
										"Enter correct Username and password", 1000).show();
							}
							}
						}
//						cursoremp.close();
						
					}
					
					//sqlA1.close();
					Log.e("close","sqlA1");
				} else {
					Toast.makeText(getApplicationContext(),
							"Enter correct Username and password", 1000).show();
				}
			
			}
			
			/*
			if (Parameters.isNetworkAvailable(LoginHomeActivity.this)) {
				final JsonPostMethod value = new JsonPostMethod();
				new Thread(new Runnable() {
					@Override
					public void run() {
						String response = value.postmethodforlogin(uName,
								Parameters.MD5(pWord),
								Parameters.randomValue(),
								Parameters.currentTime());
						System.out.println("response val is: " + response);
						String servertime = "";
						if(response!=null&&response.length()>2){ 
						try {
							JSONObject jsonObj = new JSONObject(response);
							status = jsonObj.getString("login-status");
							JSONObject responseobj = jsonObj
									.getJSONObject("response");
							status_first = jsonObj.getString("server-user-exists");
							
							servertime = responseobj.getString("server-time");
							Parameters.loggedinusertype = jsonObj.getString("user-type");
							Parameters.usertype=jsonObj.getString("user-type");
							System.out.println("response value is:"
									+ jsonObj.toString(4));
							System.out.println("response value is:" + status);

						} catch (JSONException e) {
							// TODO Auto-generated catch block
							System.out.println("servertime is:harinath" + servertime);
							e.printStackTrace();
						}
						
						String select = "select *from "
								+ DatabaseForDemo.MISCELLANEOUS_TABLE;
						DatabaseForDemo sqlA1 = new DatabaseForDemo(
								getApplicationContext());
						 dbF1 = dbforloginlogoutWrite.
						Cursor cursor = dbF1.rawQuery(select, null);
						if (cursor.getCount() > 0) {
							dbF1.execSQL("update "
									+ DatabaseForDemo.MISCELLANEOUS_TABLE
									+ " set "
									+ DatabaseForDemo.MISCEL_SERVER_UPDATE_LOCAL
									+ "=\"" + servertime + "\"");
							
						} else {
							
							ContentValues contentValues1 = new ContentValues();
							contentValues1.put(DatabaseForDemo.MISCEL_STORE,
									"store1");
							contentValues1.put(DatabaseForDemo.MISCEL_PAGEURL,
									Parameters.OriginalUrl);
							contentValues1.put(
									DatabaseForDemo.MISCEL_UPDATE_LOCAL,
									Parameters.currentTime());
							contentValues1.put(
									DatabaseForDemo.MISCEL_SERVER_UPDATE_LOCAL,
									Parameters.currentTime());
							dbF1.insert(DatabaseForDemo.MISCELLANEOUS_TABLE,
									null, contentValues1);

						}
						cursor.close();
						//sqlA1.close();
						dbF1.close();
						}else{
						//	Toast.makeText(LoginHomeActivity.this, "Server Error", 1000).show();
							Log.v("errorr", "server");
						}
					}
				}).start();

				try {
					Thread.sleep(2000);
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				if(status_first.equals("true")){
				if (status.equals("true")) {
					
					DatabaseForDemo sqlA1 = 
					 dbforloginlogout = dbforloginlogoutWrite.
				//	Calendar c = Calendar.getInstance();
				//	c.add(Calendar.MINUTE,60);
				//	SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
				//	String formattedDate = df.format(c.getTime());
					
					ContentValues values = new ContentValues();
					values.put(DatabaseForDemo.LOGIN_EMPLOYEE_NAME, uName);
					values.put(DatabaseForDemo.LOGIN_EMPLOYEE_ID, uName);
					values.put(DatabaseForDemo.LOGIN_TIME, Parameters.logintime);
					values.put(DatabaseForDemo.LOGOUT_TIME, "");
					values.put(DatabaseForDemo.DIFF_MINUTES, "00");
					values.put(DatabaseForDemo.DIFF_HOURS, "00");
					values.put(DatabaseForDemo.WAGES, "");
					values.put(DatabaseForDemo.CREATED_DATE, Parameters.currentTime());
					values.put(DatabaseForDemo.MODIFIED_DATE, Parameters.currentTime());
					values.put(DatabaseForDemo.MODIFIED_IN, "Local");
					values.put(DatabaseForDemo.SESSIONIDVAL, Parameters.sessionidforloginlogout);
					dbforloginlogout.insert(DatabaseForDemo.LOGIN_LOGOUT_TABLE, null, values);
					
					dbforloginlogout.close();
					//sqlA1.close();
					
					Parameters.userid = uName;
					userName.setText("");
					passWord.setText("");
					Parameters.usertypeloginvalue = uName;
					System.out.println("username is:"
							+ Parameters.usertypeloginvalue);
					System.out.println("user type is:"
							+ Parameters.loggedinusertype);
					Parameters.inventory_permission = true;
					System.out.println("inventory permission is:"
							+ Parameters.inventory_permission);
					Parameters.reports_permission = true;
					System.out.println("reports permission is:"
							+ Parameters.reports_permission);
					Parameters.settings_permission = true;
					System.out.println("settings_permission permission is:"
							+ Parameters.settings_permission);
					Parameters.customer_permission = true;
					System.out.println("customer_permission permission is:"
							+ Parameters.customer_permission);
					Parameters.allow_exit_permission = true;
					System.out.println("allow_exit_permission permission is:"
							+ Parameters.allow_exit_permission);
					Parameters.delete_items_permission = true;
					System.out.println("delete_items_permission permission is:"
							+ Parameters.delete_items_permission);
					Parameters.end_transaction_permission = true;
					System.out
							.println("end_transaction_permission permission is:"
									+ Parameters.end_transaction_permission);
					Parameters.force_credit_cards_permission = true;
					System.out
							.println("force_credit_cards_permission permission is:"
									+ Parameters.force_credit_cards_permission);
					Parameters.invoice_discounts_permission = true;
					System.out
							.println("invoice_discounts_permission permission is:"
									+ Parameters.invoice_discounts_permission);
					Parameters.vendor_payouts_permission = true;
					System.out
							.println("vendor_payouts_permission permission is:"
									+ Parameters.vendor_payouts_permission );
					Parameters.void_invoices_permission = true;
					System.out
							.println( "void_invoices_permission permission is:"
									+ Parameters.void_invoices_permission );
					Parameters.hold_print_permission = true;
					System.out.println("hold_print_permission permission is:"
							+ Parameters.hold_print_permission);
					Parameters.end_cash_transaction_permission = true;
					System.out
							.println("end_cash_transaction_permission permission is:"
									+ Parameters.end_cash_transaction_permission);
					Parameters.invoice_price_change_permission = true;
					System.out
							.println("invoice_price_change_permission permission is:"
									+ Parameters.invoice_price_change_permission);
					Intent intent = new Intent(LoginHomeActivity.this,
							MenuActivity.class);
					startActivity(intent);
					permissions();
				} else {
					Toast.makeText(getApplicationContext(),
							"Enter correct Username and password", 1000).show();
				}
				}else{


					DatabaseForDemo demodbH1 = new DatabaseForDemo(
							LoginHomeActivity.this);
					Cursor cursorlogin = demodbH1.getReadableDatabase().rawQuery(
							"select * from " + DatabaseForDemo.ADMIN_TABLE+" where "+DatabaseForDemo.USERID+"='"+uName+"' and "
					+DatabaseForDemo.PASSWORD+"='"+Parameters.MD5(pWord)+"';", null);
					if (cursorlogin.getCount() > 0) {
						Intent intent = new Intent(LoginHomeActivity.this,
								MenuActivity.class);
						startActivity(intent);
						permissions();
						cursorlogin.close();
						demodbH1.close();
					} else {
						cursorlogin.close();
						Cursor cursoremp = demodbH1.getReadableDatabase().rawQuery(
								"select * from " + DatabaseForDemo.EMPLOYEE_TABLE+" where "+DatabaseForDemo.EMPLOYEE_EMPLOYEE_ID+"='"+uName+"' and "
										+DatabaseForDemo.EMPLOYEE_PASSWORD+"='"+Parameters.MD5(pWord)+"';",
								null);
						if (cursoremp.getCount() > 0) {
							cursoremp.close();
							demodbH1.close();
								Toast.makeText(getApplicationContext(),
										"WelCome to admin", 1000).show();
								
								DatabaseForDemo sqlA1 = 
								 dbforloginlogout = dbforloginlogoutWrite.
							//	Calendar c = Calendar.getInstance();
							//	c.add(Calendar.MINUTE,60);
							//	SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
							//	String formattedDate = df.format(c.getTime());
								
								ContentValues values = new ContentValues();
								values.put(DatabaseForDemo.LOGIN_EMPLOYEE_NAME, uName);
								values.put(DatabaseForDemo.LOGIN_EMPLOYEE_ID, uName);
								values.put(DatabaseForDemo.LOGIN_TIME, Parameters.logintime);
								values.put(DatabaseForDemo.LOGOUT_TIME, "");
								values.put(DatabaseForDemo.DIFF_MINUTES, "00");
								values.put(DatabaseForDemo.DIFF_HOURS, "00");
								values.put(DatabaseForDemo.WAGES, "");
								values.put(DatabaseForDemo.CREATED_DATE, Parameters.currentTime());
								values.put(DatabaseForDemo.MODIFIED_DATE, Parameters.currentTime());
								values.put(DatabaseForDemo.MODIFIED_IN, "Local");
								values.put(DatabaseForDemo.SESSIONIDVAL, Parameters.sessionidforloginlogout);
								dbforloginlogout.insert(DatabaseForDemo.LOGIN_LOGOUT_TABLE, null, values);
								
								dbforloginlogout.close();
								//sqlA1.close();
								Parameters.loggedinusertype = "admin";
								Parameters.usertype="admin";
								Parameters.userid = "01";
								userName.setText("");
								passWord.setText("");
								Parameters.usertypeloginvalue = "01";
								
								System.out.println("username is:"
										+ Parameters.usertypeloginvalue);
								System.out.println("user type is:"
										+ Parameters.loggedinusertype);
								Parameters.inventory_permission = true;
								System.out.println("inventory permission is:"
										+ Parameters.inventory_permission);
								Parameters.reports_permission = true;
								System.out.println("reports permission is:"
										+ Parameters.reports_permission);
								Parameters.settings_permission = true;
								System.out
										.println("settings_permission permission is:"
												+ Parameters.settings_permission);
								Parameters.customer_permission = true;
								System.out
										.println("customer_permission permission is:"
												+ Parameters.customer_permission);
								Parameters.allow_exit_permission = true;
								System.out
										.println("allow_exit_permission permission is:"
												+ Parameters.allow_exit_permission);
								Parameters.delete_items_permission = true;
								System.out
										.println("delete_items_permission permission is:"
												+ Parameters.delete_items_permission);
								Parameters.end_transaction_permission = true;
								System.out
										.println("end_transaction_permission permission is:"
												+ Parameters.end_transaction_permission);
								Parameters.force_credit_cards_permission = true;
								System.out
										.println("force_credit_cards_permission permission is:"
												+ Parameters.force_credit_cards_permission);
								Parameters.invoice_discounts_permission = true;
								System.out
										.println("invoice_discounts_permission permission is:"
												+ Parameters.invoice_discounts_permission);
								Parameters.vendor_payouts_permission = true;
								System.out
										.println("vendor_payouts_permission permission is:"
												+ Parameters.vendor_payouts_permission);
								Parameters.void_invoices_permission = true;
								System.out
										.println("void_invoices_permission permission is:"
												+ Parameters.void_invoices_permission);
								Parameters.hold_print_permission = true;
								System.out
										.println("hold_print_permission permission is:"
												+ Parameters.hold_print_permission);
								Parameters.end_cash_transaction_permission = true;
								System.out
										.println("end_cash_transaction_permission permission is:"
												+ Parameters.end_cash_transaction_permission);
								Parameters.invoice_price_change_permission = true;
								System.out
										.println("invoice_price_change_permission permission is:"
												+ Parameters.invoice_price_change_permission);

								Intent intent = new Intent(LoginHomeActivity.this,
										MenuActivity.class);
								startActivity(intent);
								permissions();
								bool = false;
								uName="";
								pWord="";
							} else {
								Toast.makeText(getApplicationContext(),
										"Enter correct Username and password", 1000)
										.show();
							}
						}
					} else {
						Cursor cursoremp = demodbH1.getReadableDatabase().rawQuery(
								"select * from " + DatabaseForDemo.EMPLOYEE_TABLE+" where "+DatabaseForDemo.EMPLOYEE_EMPLOYEE_ID+"='"+uName+"' and "
										+DatabaseForDemo.EMPLOYEE_PASSWORD+"='"+Parameters.MD5(pWord)+"';",
								null);
						if (cursoremp.getCount() > 0) {
							Intent intent = new Intent(LoginHomeActivity.this,
									MenuActivity.class);
							startActivity(intent);
							permissions();
							cursoremp.close();
							demodbH1.close();
							finish();
						} else {
							cursoremp.close();
							demodbH1.close();
							if (uName.equals("01") && pWord.equals("admin")) {
								Toast.makeText(getApplicationContext(),
										"WelCome to admin", 1000).show();
								
								DatabaseForDemo sqlA1 = 
								 dbforloginlogout = dbforloginlogoutWrite.
								
								ContentValues values = new ContentValues();
								values.put(DatabaseForDemo.LOGIN_EMPLOYEE_NAME, uName);
								values.put(DatabaseForDemo.LOGIN_EMPLOYEE_ID, uName);
								values.put(DatabaseForDemo.LOGIN_TIME, Parameters.logintime);
								values.put(DatabaseForDemo.LOGOUT_TIME, "");
								values.put(DatabaseForDemo.DIFF_MINUTES, "00");
								values.put(DatabaseForDemo.DIFF_HOURS, "00");
								values.put(DatabaseForDemo.WAGES, "");
								values.put(DatabaseForDemo.CREATED_DATE, Parameters.currentTime());
								values.put(DatabaseForDemo.MODIFIED_DATE, Parameters.currentTime());
								values.put(DatabaseForDemo.MODIFIED_IN, "Local");
								values.put(DatabaseForDemo.SESSIONIDVAL, Parameters.sessionidforloginlogout);
								dbforloginlogout.insert(DatabaseForDemo.LOGIN_LOGOUT_TABLE, null, values);
								
								dbforloginlogout.close();
								//sqlA1.close();
								Parameters.loggedinusertype = "admin";
								Parameters.usertype="admin";
								Parameters.userid = "01";
								userName.setText("");
								passWord.setText("");
								Parameters.usertypeloginvalue = "01";
								
								System.out.println("username is:"
										+ Parameters.usertypeloginvalue);
								System.out.println("user type is:"
										+ Parameters.loggedinusertype);
								Parameters.inventory_permission = true;
								System.out.println("inventory permission is:"
										+ Parameters.inventory_permission);
								Parameters.reports_permission = true;
								System.out.println("reports permission is:"
										+ Parameters.reports_permission);
								Parameters.settings_permission = true;
								System.out
										.println("settings_permission permission is:"
												+ Parameters.settings_permission);
								Parameters.customer_permission = true;
								System.out
										.println("customer_permission permission is:"
												+ Parameters.customer_permission);
								Parameters.allow_exit_permission = true;
								System.out
										.println("allow_exit_permission permission is:"
												+ Parameters.allow_exit_permission);
								Parameters.delete_items_permission = true;
								System.out
										.println("delete_items_permission permission is:"
												+ Parameters.delete_items_permission);
								Parameters.end_transaction_permission = true;
								System.out
										.println("end_transaction_permission permission is:"
												+ Parameters.end_transaction_permission);
								Parameters.force_credit_cards_permission = true;
								System.out
										.println("force_credit_cards_permission permission is:"
												+ Parameters.force_credit_cards_permission);
								Parameters.invoice_discounts_permission = true;
								System.out
										.println("invoice_discounts_permission permission is:"
												+ Parameters.invoice_discounts_permission);
								Parameters.vendor_payouts_permission = true;
								System.out
										.println("vendor_payouts_permission permission is:"
												+ Parameters.vendor_payouts_permission);
								Parameters.void_invoices_permission = true;
								System.out
										.println("void_invoices_permission permission is:"
												+ Parameters.void_invoices_permission);
								Parameters.hold_print_permission = true;
								System.out
										.println("hold_print_permission permission is:"
												+ Parameters.hold_print_permission);
								Parameters.end_cash_transaction_permission = true;
								System.out
										.println("end_cash_transaction_permission permission is:"
												+ Parameters.end_cash_transaction_permission);
								Parameters.invoice_price_change_permission = true;
								System.out
										.println("invoice_price_change_permission permission is:"
												+ Parameters.invoice_price_change_permission);

								Intent intent = new Intent(LoginHomeActivity.this,
										MenuActivity.class);
								startActivity(intent);
								permissions();
								bool = false;
								uName="";
								pWord="";
							} else {
								Toast.makeText(getApplicationContext(),
										"Enter correct Username and password", 1000)
										.show();
							}
						}
					}

					DatabaseForDemo demodbG1 = new DatabaseForDemo(
							LoginHomeActivity.this);

					if (uName != null && pWord != null) {
						String demouserid = null, demopassword = null, pwdmd5 = null;
						ArrayList<String> employeeuserid = new ArrayList<String>();
						ArrayList<String> employeepassword = new ArrayList<String>();
						pwdmd5 = Parameters.MD5(pWord);
						System.out.println("password md5 val is....:" + pwdmd5);
						Cursor cursor = demodbG1.getReadableDatabase().rawQuery(
								"select *from admin_details where userid=\"" + uName
										+ "\" and password=\"" + pWord + "\"", null);
						System.out.println(  );

						Cursor cursoremployee = demodbG1
								.getReadableDatabase()
								.rawQuery(
										"select *from "
												+ DatabaseForDemo.EMPLOYEE_TABLE
												+ " where "
												+ DatabaseForDemo.EMPLOYEE_EMPLOYEE_ID
												+ "=\"" + uName + "\" and "
												+ DatabaseForDemo.EMPLOYEE_PASSWORD
												+ "=\"" + pwdmd5 + "\"", null);
						System.out.println("employee cursor count is:"
								+ cursoremployee.getCount());

						if (cursor.getCount() > 0) {
							if (cursor != null) {
								if (cursor.moveToFirst()) {
									do {
										demouserid = cursor
												.getString(cursor
														.getColumnIndex(DatabaseForDemo.USERID));
										demopassword = cursor
												.getString(cursor
														.getColumnIndex(DatabaseForDemo.PASSWORD));
									} while (cursor.moveToNext());
								}
							}
						}
						cursor.close();
						if (cursoremployee.getCount() > 0) {
							if (cursoremployee != null) {
								if (cursoremployee.moveToFirst()) {
									do {
										String employeeuseridval = cursoremployee
												.getString(cursoremployee
														.getColumnIndex(DatabaseForDemo.EMPLOYEE_EMPLOYEE_ID));
										employeeuserid.add(employeeuseridval);
										String employeepasswordval = cursoremployee
												.getString(cursoremployee
														.getColumnIndex(DatabaseForDemo.EMPLOYEE_PASSWORD));
										employeepassword.add(employeepasswordval);
									} while (cursoremployee.moveToNext());
								}
							}
						}
						cursoremployee.close();
						System.out.println("demo userid val is:" + demouserid);
						System.out.println("demo password val is:" + demopassword);
						System.out.println("employee userid val is:"
								+ employeeuserid);
						System.out.println("employee password val is:"
								+ employeepassword);

						if (uName.equals(demouserid) && pWord.equals(demopassword)) {
							Toast.makeText(getApplicationContext(),
									"WelCome to demo", 1000).show();
							
							DatabaseForDemo sqlA1 = 
							 dbforloginlogout = dbforloginlogoutWrite.
						//	Calendar c = Calendar.getInstance();
						//	c.add(Calendar.MINUTE,60);
						//	SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
						//	String formattedDate = df.format(c.getTime());
							
							ContentValues values = new ContentValues();
							values.put(DatabaseForDemo.LOGIN_EMPLOYEE_NAME, uName);
							values.put(DatabaseForDemo.LOGIN_EMPLOYEE_ID, uName);
							values.put(DatabaseForDemo.LOGIN_TIME, Parameters.logintime);
							values.put(DatabaseForDemo.LOGOUT_TIME, "");
							values.put(DatabaseForDemo.DIFF_MINUTES, "00");
							values.put(DatabaseForDemo.DIFF_HOURS, "00");
							values.put(DatabaseForDemo.WAGES, "");
							values.put(DatabaseForDemo.CREATED_DATE, Parameters.currentTime());
							values.put(DatabaseForDemo.MODIFIED_DATE, Parameters.currentTime());
							values.put(DatabaseForDemo.MODIFIED_IN, "Local");
							values.put(DatabaseForDemo.SESSIONIDVAL, Parameters.sessionidforloginlogout);
							dbforloginlogout.insert(DatabaseForDemo.LOGIN_LOGOUT_TABLE, null, values);
							
							dbforloginlogout.close();
							//sqlA1.close();
							Parameters.userid = demouserid;
							userName.setText("");
							passWord.setText("");
							Parameters.usertypeloginvalue = demouserid;
							Parameters.loggedinusertype = "admin";
							Parameters.usertype="admin";
							System.out.println("username is:"
									+ Parameters.usertypeloginvalue);
							System.out.println("user type is:"
									+ Parameters.loggedinusertype);
							Parameters.inventory_permission = true;
							System.out.println("inventory permission is:"
									+ Parameters.inventory_permission);
							Parameters.reports_permission = true;
							System.out.println("reports permission is:"
									+ Parameters.reports_permission);
							Parameters.settings_permission = true;
							System.out.println("settings_permission permission is:"
									+ Parameters.settings_permission);
							Parameters.customer_permission = true;
							System.out.println("customer_permission permission is:"
									+ Parameters.customer_permission);
							Parameters.allow_exit_permission = true;
							System.out
									.println("allow_exit_permission permission is:"
											+ Parameters.allow_exit_permission);
							Parameters.delete_items_permission = true;
							System.out
									.println("delete_items_permission permission is:"
											+ Parameters.delete_items_permission);
							Parameters.end_transaction_permission = true;
							System.out
									.println("end_transaction_permission permission is:"
											+ Parameters.end_transaction_permission);
							Parameters.force_credit_cards_permission = true;
							System.out
									.println("force_credit_cards_permission permission is:"
											+ Parameters.force_credit_cards_permission);
							Parameters.invoice_discounts_permission = true;
							System.out
									.println("invoice_discounts_permission permission is:"
											+ Parameters.invoice_discounts_permission);
							Parameters.vendor_payouts_permission = true;
							System.out
									.println("vendor_payouts_permission permission is:"
											+ Parameters.vendor_payouts_permission);
							Parameters.void_invoices_permission = true;
							System.out
									.println("void_invoices_permission permission is:"
											+ Parameters.void_invoices_permission);
							Parameters.hold_print_permission = true;
							System.out
									.println("hold_print_permission permission is:"
											+ Parameters.hold_print_permission);
							Parameters.end_cash_transaction_permission = true;
							System.out
									.println("end_cash_transaction_permission permission is:"
											+ Parameters.end_cash_transaction_permission);
							Parameters.invoice_price_change_permission = true;
							System.out
									.println("invoice_price_change_permission permission is:"
											+ Parameters.invoice_price_change_permission);
							demodbG1.close();
							Intent intent = new Intent(LoginHomeActivity.this,
									MenuActivity.class);
							startActivity(intent);
							permissions();
						} else if (employeeuserid.contains(uName)
								&& employeepassword.contains(Parameters.MD5(pWord))) {
							Toast.makeText(getApplicationContext(),
									"WelCome to employee", 1000).show();
							
							DatabaseForDemo sqlA1 = 
							 dbforloginlogout = dbforloginlogoutWrite.
							
							ContentValues values = new ContentValues();
							values.put(DatabaseForDemo.LOGIN_EMPLOYEE_NAME, uName);
							values.put(DatabaseForDemo.LOGIN_EMPLOYEE_ID, uName);
							values.put(DatabaseForDemo.LOGIN_TIME, Parameters.logintime);
							values.put(DatabaseForDemo.LOGOUT_TIME, "");
							values.put(DatabaseForDemo.DIFF_MINUTES, "00");
							values.put(DatabaseForDemo.DIFF_HOURS, "00");
							values.put(DatabaseForDemo.WAGES, "");
							values.put(DatabaseForDemo.CREATED_DATE, Parameters.currentTime());
							values.put(DatabaseForDemo.MODIFIED_DATE, Parameters.currentTime());
							values.put(DatabaseForDemo.MODIFIED_IN, "Local");
							values.put(DatabaseForDemo.SESSIONIDVAL, Parameters.sessionidforloginlogout);
							dbforloginlogout.insert(DatabaseForDemo.LOGIN_LOGOUT_TABLE, null, values);
							
							dbforloginlogout.close();
							//sqlA1.close();
							
							Parameters.userid = uName;
							Parameters.usertypeloginvalue = uName;
							Parameters.loggedinusertype = "employee";
							Parameters.usertype="employee";
							System.out.println("username is:"
									+ Parameters.usertypeloginvalue);
							System.out.println("user type is:"
									+ Parameters.loggedinusertype);
							Cursor cursoremployeepermission = demodbG1
									.getReadableDatabase()
									.rawQuery(
											"select *from "
													+ DatabaseForDemo.EMP_PERMISSIONS_TABLE
													+ " where "
													+ DatabaseForDemo.EMPLOYEE_EMPLOYEE_ID
													+ "=\"" + uName + "\"", null);
							if (cursoremployeepermission != null) {
								if (cursoremployeepermission.moveToFirst()) {
									do {
										String inventory = cursoremployeepermission
												.getString(cursoremployeepermission
														.getColumnIndex(DatabaseForDemo.EMP_INVENTORY));
										if (inventory.equals("Enable")) {
											Parameters.inventory_permission = true;
										} else {
											Parameters.inventory_permission = false;
										}
										System.out
												.println("inventory permission is:"
														+ Parameters.inventory_permission);
										String customer = cursoremployeepermission
												.getString(cursoremployeepermission
														.getColumnIndex(DatabaseForDemo.EMP_CUSTOMERS));
										if (customer.equals("Enable")) {
											Parameters.customer_permission = true;
										} else {
											Parameters.customer_permission = false;
										}
										System.out
												.println("customer_permission permission is:"
														+ Parameters.customer_permission);
										String reports = cursoremployeepermission
												.getString(cursoremployeepermission
														.getColumnIndex(DatabaseForDemo.EMP_REPORTS));
										if (reports.equals("Enable")) {
											Parameters.reports_permission = true;
										} else {
											Parameters.reports_permission = false;
										}
										System.out.println("reports permission is:"
												+ Parameters.reports_permission);
										String discounts = cursoremployeepermission
												.getString(cursoremployeepermission
														.getColumnIndex(DatabaseForDemo.EMP_DISCOUNTS));
										if (discounts.equals("Enable")) {
											Parameters.invoice_discounts_permission = true;
										} else {
											Parameters.invoice_discounts_permission = false;
										}
										System.out
												.println("invoice_discounts_permission permission is:"
														+ Parameters.invoice_discounts_permission);
										String settings = cursoremployeepermission
												.getString(cursoremployeepermission
														.getColumnIndex(DatabaseForDemo.EMP_SETTINGS));
										if (settings.equals("Enable")) {
											Parameters.settings_permission = true;
										} else {
											Parameters.settings_permission = false;
										}
										System.out
												.println("settings_permission permission is:"
														+ Parameters.settings_permission);
										String pricechange = cursoremployeepermission
												.getString(cursoremployeepermission
														.getColumnIndex(DatabaseForDemo.EMP_PRICE));
										if (pricechange.equals("Enable")) {
											Parameters.invoice_price_change_permission = true;
										} else {
											Parameters.invoice_price_change_permission = false;
										}
										System.out
												.println("invoice_price_change_permission permission is:"
														+ Parameters.invoice_price_change_permission);
										String allowexit = cursoremployeepermission
												.getString(cursoremployeepermission
														.getColumnIndex(DatabaseForDemo.EMP_EXIT));
										if (allowexit.equals("Enable")) {
											Parameters.allow_exit_permission = true;
										} else {
											Parameters.allow_exit_permission = false;
										}
										System.out
												.println("allow_exit_permission permission is:"
														+ Parameters.allow_exit_permission);
										String payouts = cursoremployeepermission
												.getString(cursoremployeepermission
														.getColumnIndex(DatabaseForDemo.EMP_PAYOUTS));
										if (payouts.equals("Enable")) {
											Parameters.vendor_payouts_permission = true;
										} else {
											Parameters.vendor_payouts_permission = false;
										}
										System.out
												.println("vendor_payouts_permission permission is:"
														+ Parameters.vendor_payouts_permission);
										String delete = cursoremployeepermission
												.getString(cursoremployeepermission
														.getColumnIndex(DatabaseForDemo.EMP_DELETE));
										if (delete.equals("Enable")) {
											Parameters.delete_items_permission = true;
										} else {
											Parameters.delete_items_permission = false;
										}
										System.out
												.println("delete_items_permission permission is:"
														+ Parameters.delete_items_permission);
										String voiddata = cursoremployeepermission
												.getString(cursoremployeepermission
														.getColumnIndex(DatabaseForDemo.EMP_VOID));
										if (voiddata.equals("Enable")) {
											Parameters.void_invoices_permission = true;
										} else {
											Parameters.void_invoices_permission = false;
										}
										System.out
												.println("void_invoices_permission permission is:"
														+ Parameters.void_invoices_permission);
										String transactions = cursoremployeepermission
												.getString(cursoremployeepermission
														.getColumnIndex(DatabaseForDemo.EMP_TRANSACTIONS));
										if (transactions.equals("Enable")) {
											Parameters.end_transaction_permission = true;
										} else {
											Parameters.end_transaction_permission = false;
										}
										System.out
												.println("end_transaction_permission permission is:"
														+ Parameters.end_transaction_permission);
										String holdprint = cursoremployeepermission
												.getString(cursoremployeepermission
														.getColumnIndex(DatabaseForDemo.EMP_HOLDPRINTS));
										if (holdprint.equals("Enable")) {
											Parameters.hold_print_permission = true;
										} else {
											Parameters.hold_print_permission = false;
										}
										System.out
												.println("hold_print_permission permission is:"
														+ Parameters.hold_print_permission);
										String credit = cursoremployeepermission
												.getString(cursoremployeepermission
														.getColumnIndex(DatabaseForDemo.EMP_CREDIT));
										if (credit.equals("Enable")) {
											Parameters.force_credit_cards_permission = true;
										} else {
											Parameters.force_credit_cards_permission = false;
										}
										System.out
												.println("force_credit_cards_permission permission is:"
														+ Parameters.force_credit_cards_permission);
										String endcash = cursoremployeepermission
												.getString(cursoremployeepermission
														.getColumnIndex(DatabaseForDemo.EMP_ENDCASH));
										if (endcash.equals("Enable")) {
											Parameters.end_cash_transaction_permission = true;
										} else {
											Parameters.end_cash_transaction_permission = false;
										}
										System.out
												.println("end_cash_transaction_permission permission is:"
														+ Parameters.end_cash_transaction_permission);

									} while (cursoremployeepermission.moveToNext());
								}
							}
							cursoremployeepermission.close();
							String parameterval = "?username=" + uName
									+ "&password=" + pwdmd5 + "&deviceid="
									+ Parameters.randomValue() + "&systemtime="
									+ Parameters.currentTime().replace(" ", "%20");
							ContentValues contentValues1 = new ContentValues();
							contentValues1.put(DatabaseForDemo.QUERY_TYPE,
									"userlogin");
							contentValues1.put(DatabaseForDemo.PENDING_USER_ID,
									Parameters.userid);
							contentValues1.put(DatabaseForDemo.PAGE_URL,
									"user-login.php");
							contentValues1.put(DatabaseForDemo.TABLE_NAME_PENDING,
									"");
							contentValues1.put(
									DatabaseForDemo.CURRENT_TIME_PENDING,
									Parameters.currentTime());
							contentValues1.put(DatabaseForDemo.PARAMETERS,
									parameterval);
							demodbG1.getWritableDatabase().insert(
									DatabaseForDemo.PENDING_QUERIES_TABLE, null,
									contentValues1);
							userName.setText("");
							passWord.setText("");

							Intent intent = new Intent(LoginHomeActivity.this,
									MenuActivity.class);
							startActivity(intent);
							permissions();

						} else {

							
								Toast.makeText(getApplicationContext(),
										"Enter correct Username and password", 1000)
										.show();
						}

					} else {
						if (bool)
						Toast.makeText(getApplicationContext(),
								"Enter username and password", 1000).show();
					}
					demodbG1.close();
				
				}}
			} else {

				DatabaseForDemo demodbH1 = new DatabaseForDemo(
						LoginHomeActivity.this);
				Cursor cursorlogin = demodbH1.getReadableDatabase().rawQuery(
						"select * from " + DatabaseForDemo.ADMIN_TABLE+" where "+DatabaseForDemo.USERID+"='"+uName+"' and "
				+DatabaseForDemo.PASSWORD+"='"+Parameters.MD5(pWord)+"';", null);
				if (cursorlogin.getCount() > 0) {
					Intent intent = new Intent(LoginHomeActivity.this,
							MenuActivity.class);
					startActivity(intent);
					permissions();
					cursorlogin.close();
					demodbH1.close();
				} else {
					cursorlogin.close();
					Cursor cursoremp = demodbH1.getReadableDatabase().rawQuery(
							"select * from " + DatabaseForDemo.EMPLOYEE_TABLE+" where "+DatabaseForDemo.EMPLOYEE_EMPLOYEE_ID+"='"+uName+"' and "
									+DatabaseForDemo.EMPLOYEE_PASSWORD+"='"+Parameters.MD5(pWord)+"';",
							null);
					if (cursoremp.getCount() > 0) {
						cursoremp.close();
						demodbH1.close();
							Toast.makeText(getApplicationContext(),
									"WelCome to admin", 1000).show();
							
							DatabaseForDemo sqlA1 = 
							 dbforloginlogout = dbforloginlogoutWrite.
						//	Calendar c = Calendar.getInstance();
						//	c.add(Calendar.MINUTE,60);
						//	SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
						//	String formattedDate = df.format(c.getTime());
							
							ContentValues values = new ContentValues();
							values.put(DatabaseForDemo.LOGIN_EMPLOYEE_NAME, uName);
							values.put(DatabaseForDemo.LOGIN_EMPLOYEE_ID, uName);
							values.put(DatabaseForDemo.LOGIN_TIME, Parameters.logintime);
							values.put(DatabaseForDemo.LOGOUT_TIME, "");
							values.put(DatabaseForDemo.DIFF_MINUTES, "00");
							values.put(DatabaseForDemo.DIFF_HOURS, "00");
							values.put(DatabaseForDemo.WAGES, "");
							values.put(DatabaseForDemo.CREATED_DATE, Parameters.currentTime());
							values.put(DatabaseForDemo.MODIFIED_DATE, Parameters.currentTime());
							values.put(DatabaseForDemo.MODIFIED_IN, "Local");
							values.put(DatabaseForDemo.SESSIONIDVAL, Parameters.sessionidforloginlogout);
							dbforloginlogout.insert(DatabaseForDemo.LOGIN_LOGOUT_TABLE, null, values);
							
							dbforloginlogout.close();
							//sqlA1.close();
							Parameters.loggedinusertype = "admin";
							Parameters.usertype="admin";
							Parameters.userid = "01";
							userName.setText("");
							passWord.setText("");
							Parameters.usertypeloginvalue = "01";
							
							System.out.println("username is:"
									+ Parameters.usertypeloginvalue);
							System.out.println("user type is:"
									+ Parameters.loggedinusertype);
							Parameters.inventory_permission = true;
							System.out.println("inventory permission is:"
									+ Parameters.inventory_permission);
							Parameters.reports_permission = true;
							System.out.println("reports permission is:"
									+ Parameters.reports_permission);
							Parameters.settings_permission = true;
							System.out
									.println("settings_permission permission is:"
											+ Parameters.settings_permission);
							Parameters.customer_permission = true;
							System.out
									.println("customer_permission permission is:"
											+ Parameters.customer_permission);
							Parameters.allow_exit_permission = true;
							System.out
									.println("allow_exit_permission permission is:"
											+ Parameters.allow_exit_permission);
							Parameters.delete_items_permission = true;
							System.out
									.println("delete_items_permission permission is:"
											+ Parameters.delete_items_permission);
							Parameters.end_transaction_permission = true;
							System.out
									.println("end_transaction_permission permission is:"
											+ Parameters.end_transaction_permission);
							Parameters.force_credit_cards_permission = true;
							System.out
									.println("force_credit_cards_permission permission is:"
											+ Parameters.force_credit_cards_permission);
							Parameters.invoice_discounts_permission = true;
							System.out
									.println("invoice_discounts_permission permission is:"
											+ Parameters.invoice_discounts_permission);
							Parameters.vendor_payouts_permission = true;
							System.out
									.println("vendor_payouts_permission permission is:"
											+ Parameters.vendor_payouts_permission);
							Parameters.void_invoices_permission = true;
							System.out
									.println("void_invoices_permission permission is:"
											+ Parameters.void_invoices_permission);
							Parameters.hold_print_permission = true;
							System.out
									.println("hold_print_permission permission is:"
											+ Parameters.hold_print_permission);
							Parameters.end_cash_transaction_permission = true;
							System.out
									.println("end_cash_transaction_permission permission is:"
											+ Parameters.end_cash_transaction_permission);
							Parameters.invoice_price_change_permission = true;
							System.out
									.println("invoice_price_change_permission permission is:"
											+ Parameters.invoice_price_change_permission);

							Intent intent = new Intent(LoginHomeActivity.this,
									MenuActivity.class);
							startActivity(intent);
							 permissions();
							bool = false;
							uName="";
							pWord="";
						} else {
							Toast.makeText(getApplicationContext(),
									"Enter correct Username and password", 1000)
									.show();
						}
					}
				}

				DatabaseForDemo demodbG1 = new DatabaseForDemo(
						LoginHomeActivity.this);

				if (uName != null && pWord != null) {
					String demouserid = null, demopassword = null, pwdmd5 = null;
					ArrayList<String> employeeuserid = new ArrayList<String>();
					ArrayList<String> employeepassword = new ArrayList<String>();
					pwdmd5 = Parameters.MD5(pWord);
					System.out.println("password md5 val is....:" + pwdmd5);
					Cursor cursor = demodbG1.getReadableDatabase().rawQuery(
							"select *from admin_details where userid=\"" + uName
									+ "\" and password=\"" + pWord + "\"", null);
					System.out.println(  );

					Cursor cursoremployee = demodbG1
							.getReadableDatabase()
							.rawQuery(
									"select *from "
											+ DatabaseForDemo.EMPLOYEE_TABLE
											+ " where "
											+ DatabaseForDemo.EMPLOYEE_EMPLOYEE_ID
											+ "=\"" + uName + "\" and "
											+ DatabaseForDemo.EMPLOYEE_PASSWORD
											+ "=\"" + pwdmd5 + "\"", null);
					System.out.println("employee cursor count is:"
							+ cursoremployee.getCount());

					if (cursor.getCount() > 0) {
						if (cursor != null) {
							if (cursor.moveToFirst()) {
								do {
									demouserid = cursor
											.getString(cursor
													.getColumnIndex(DatabaseForDemo.USERID));
									demopassword = cursor
											.getString(cursor
													.getColumnIndex(DatabaseForDemo.PASSWORD));
								} while (cursor.moveToNext());
							}
						}
					}
					cursor.close();
					if (cursoremployee.getCount() > 0) {
						if (cursoremployee != null) {
							if (cursoremployee.moveToFirst()) {
								do {
									String employeeuseridval = cursoremployee
											.getString(cursoremployee
													.getColumnIndex(DatabaseForDemo.EMPLOYEE_EMPLOYEE_ID));
									employeeuserid.add(employeeuseridval);
									String employeepasswordval = cursoremployee
											.getString(cursoremployee
													.getColumnIndex(DatabaseForDemo.EMPLOYEE_PASSWORD));
									employeepassword.add(employeepasswordval);
								} while (cursoremployee.moveToNext());
							}
						}
					}
					cursoremployee.close();
					System.out.println("demo userid val is:" + demouserid);
					System.out.println("demo password val is:" + demopassword);
					System.out.println("employee userid val is:"
							+ employeeuserid);
					System.out.println("employee password val is:"
							+ employeepassword);

					if (uName.equals(demouserid) && pWord.equals(demopassword)) {
						Toast.makeText(getApplicationContext(),
								"WelCome to demo", 1000).show();
						
						DatabaseForDemo sqlA1 = 
						 dbforloginlogout = dbforloginlogoutWrite.
					//	Calendar c = Calendar.getInstance();
					//	c.add(Calendar.MINUTE,60);
					//	SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
					//	String formattedDate = df.format(c.getTime());
						
						ContentValues values = new ContentValues();
						values.put(DatabaseForDemo.LOGIN_EMPLOYEE_NAME, uName);
						values.put(DatabaseForDemo.LOGIN_EMPLOYEE_ID, uName);
						values.put(DatabaseForDemo.LOGIN_TIME, Parameters.logintime);
						values.put(DatabaseForDemo.LOGOUT_TIME, "");
						values.put(DatabaseForDemo.DIFF_MINUTES, "00");
						values.put(DatabaseForDemo.DIFF_HOURS, "00");
						values.put(DatabaseForDemo.WAGES, "");
						values.put(DatabaseForDemo.CREATED_DATE, Parameters.currentTime());
						values.put(DatabaseForDemo.MODIFIED_DATE, Parameters.currentTime());
						values.put(DatabaseForDemo.MODIFIED_IN, "Local");
						values.put(DatabaseForDemo.SESSIONIDVAL, Parameters.sessionidforloginlogout);
						dbforloginlogout.insert(DatabaseForDemo.LOGIN_LOGOUT_TABLE, null, values);
						
						dbforloginlogout.close();
						//sqlA1.close();
						Parameters.userid = demouserid;
						userName.setText("");
						passWord.setText("");
						Parameters.usertypeloginvalue = demouserid;
						Parameters.loggedinusertype = "admin";
						Parameters.usertype="admin";
						System.out.println("username is:"
								+ Parameters.usertypeloginvalue);
						System.out.println("user type is:"
								+ Parameters.loggedinusertype);
						Parameters.inventory_permission = true;
						System.out.println("inventory permission is:"
								+ Parameters.inventory_permission);
						Parameters.reports_permission = true;
						System.out.println("reports permission is:"
								+ Parameters.reports_permission);
						Parameters.settings_permission = true;
						System.out.println("settings_permission permission is:"
								+ Parameters.settings_permission);
						Parameters.customer_permission = true;
						System.out.println("customer_permission permission is:"
								+ Parameters.customer_permission);
						Parameters.allow_exit_permission = true;
						System.out
								.println("allow_exit_permission permission is:"
										+ Parameters.allow_exit_permission);
						Parameters.delete_items_permission = true;
						System.out
								.println("delete_items_permission permission is:"
										+ Parameters.delete_items_permission);
						Parameters.end_transaction_permission = true;
						System.out
								.println("end_transaction_permission permission is:"
										+ Parameters.end_transaction_permission);
						Parameters.force_credit_cards_permission = true;
						System.out
								.println("force_credit_cards_permission permission is:"
										+ Parameters.force_credit_cards_permission);
						Parameters.invoice_discounts_permission = true;
						System.out
								.println("invoice_discounts_permission permission is:"
										+ Parameters.invoice_discounts_permission);
						Parameters.vendor_payouts_permission = true;
						System.out
								.println("vendor_payouts_permission permission is:"
										+ Parameters.vendor_payouts_permission);
						Parameters.void_invoices_permission = true;
						System.out
								.println("void_invoices_permission permission is:"
										+ Parameters.void_invoices_permission);
						Parameters.hold_print_permission = true;
						System.out
								.println("hold_print_permission permission is:"
										+ Parameters.hold_print_permission);
						Parameters.end_cash_transaction_permission = true;
						System.out
								.println("end_cash_transaction_permission permission is:"
										+ Parameters.end_cash_transaction_permission);
						Parameters.invoice_price_change_permission = true;
						System.out
								.println("invoice_price_change_permission permission is:"
										+ Parameters.invoice_price_change_permission);
						demodbG1.close();
						Intent intent = new Intent(LoginHomeActivity.this,
								MenuActivity.class);
						startActivity(intent);
						permissions();
					} else if (employeeuserid.contains(uName)
							&& employeepassword.contains(Parameters.MD5(pWord))) {
						Toast.makeText(getApplicationContext(),
								"WelCome to employee", 1000).show();
						
						DatabaseForDemo sqlA1 = 
						 dbforloginlogout = dbforloginlogoutWrite.
					//	Calendar c = Calendar.getInstance();
					//	c.add(Calendar.MINUTE,60);
					//	SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
					//	String formattedDate = df.format(c.getTime());
						
						ContentValues values = new ContentValues();
						values.put(DatabaseForDemo.LOGIN_EMPLOYEE_NAME, uName);
						values.put(DatabaseForDemo.LOGIN_EMPLOYEE_ID, uName);
						values.put(DatabaseForDemo.LOGIN_TIME, Parameters.logintime);
						values.put(DatabaseForDemo.LOGOUT_TIME, "");
						values.put(DatabaseForDemo.DIFF_MINUTES, "00");
						values.put(DatabaseForDemo.DIFF_HOURS, "00");
						values.put(DatabaseForDemo.WAGES, "");
						values.put(DatabaseForDemo.CREATED_DATE, Parameters.currentTime());
						values.put(DatabaseForDemo.MODIFIED_DATE, Parameters.currentTime());
						values.put(DatabaseForDemo.MODIFIED_IN, "Local");
						values.put(DatabaseForDemo.SESSIONIDVAL, Parameters.sessionidforloginlogout);
						dbforloginlogout.insert(DatabaseForDemo.LOGIN_LOGOUT_TABLE, null, values);
						
						dbforloginlogout.close();
						//sqlA1.close();
						
						Parameters.userid = uName;
						Parameters.usertypeloginvalue = uName;
						Parameters.loggedinusertype = "employee";
						Parameters.usertype="employee";
						System.out.println("username is:"
								+ Parameters.usertypeloginvalue);
						System.out.println("user type is:"
								+ Parameters.loggedinusertype);
						Cursor cursoremployeepermission = demodbG1
								.getReadableDatabase()
								.rawQuery(
										"select *from "
												+ DatabaseForDemo.EMP_PERMISSIONS_TABLE
												+ " where "
												+ DatabaseForDemo.EMPLOYEE_EMPLOYEE_ID
												+ "=\"" + uName + "\"", null);
						if (cursoremployeepermission != null) {
							if (cursoremployeepermission.moveToFirst()) {
								do {
									String inventory = cursoremployeepermission
											.getString(cursoremployeepermission
													.getColumnIndex(DatabaseForDemo.EMP_INVENTORY));
									if (inventory.equals("Enable")) {
										Parameters.inventory_permission = true;
									} else {
										Parameters.inventory_permission = false;
									}
									System.out
											.println("inventory permission is:"
													+ Parameters.inventory_permission);
									String customer = cursoremployeepermission
											.getString(cursoremployeepermission
													.getColumnIndex(DatabaseForDemo.EMP_CUSTOMERS));
									if (customer.equals("Enable")) {
										Parameters.customer_permission = true;
									} else {
										Parameters.customer_permission = false;
									}
									System.out
											.println("customer_permission permission is:"
													+ Parameters.customer_permission);
									String reports = cursoremployeepermission
											.getString(cursoremployeepermission
													.getColumnIndex(DatabaseForDemo.EMP_REPORTS));
									if (reports.equals("Enable")) {
										Parameters.reports_permission = true;
									} else {
										Parameters.reports_permission = false;
									}
									System.out.println("reports permission is:"
											+ Parameters.reports_permission);
									String discounts = cursoremployeepermission
											.getString(cursoremployeepermission
													.getColumnIndex(DatabaseForDemo.EMP_DISCOUNTS));
									if (discounts.equals("Enable")) {
										Parameters.invoice_discounts_permission = true;
									} else {
										Parameters.invoice_discounts_permission = false;
									}
									System.out
											.println("invoice_discounts_permission permission is:"
													+ Parameters.invoice_discounts_permission);
									String settings = cursoremployeepermission
											.getString(cursoremployeepermission
													.getColumnIndex(DatabaseForDemo.EMP_SETTINGS));
									if (settings.equals("Enable")) {
										Parameters.settings_permission = true;
									} else {
										Parameters.settings_permission = false;
									}
									System.out
											.println("settings_permission permission is:"
													+ Parameters.settings_permission);
									String pricechange = cursoremployeepermission
											.getString(cursoremployeepermission
													.getColumnIndex(DatabaseForDemo.EMP_PRICE));
									if (pricechange.equals("Enable")) {
										Parameters.invoice_price_change_permission = true;
									} else {
										Parameters.invoice_price_change_permission = false;
									}
									System.out
											.println("invoice_price_change_permission permission is:"
													+ Parameters.invoice_price_change_permission);
									String allowexit = cursoremployeepermission
											.getString(cursoremployeepermission
													.getColumnIndex(DatabaseForDemo.EMP_EXIT));
									if (allowexit.equals("Enable")) {
										Parameters.allow_exit_permission = true;
									} else {
										Parameters.allow_exit_permission = false;
									}
									System.out
											.println("allow_exit_permission permission is:"
													+ Parameters.allow_exit_permission);
									String payouts = cursoremployeepermission
											.getString(cursoremployeepermission
													.getColumnIndex(DatabaseForDemo.EMP_PAYOUTS));
									if (payouts.equals("Enable")) {
										Parameters.vendor_payouts_permission = true;
									} else {
										Parameters.vendor_payouts_permission = false;
									}
									System.out
											.println("vendor_payouts_permission permission is:"
													+ Parameters.vendor_payouts_permission);
									String delete = cursoremployeepermission
											.getString(cursoremployeepermission
													.getColumnIndex(DatabaseForDemo.EMP_DELETE));
									if (delete.equals("Enable")) {
										Parameters.delete_items_permission = true;
									} else {
										Parameters.delete_items_permission = false;
									}
									System.out
											.println("delete_items_permission permission is:"
													+ Parameters.delete_items_permission);
									String voiddata = cursoremployeepermission
											.getString(cursoremployeepermission
													.getColumnIndex(DatabaseForDemo.EMP_VOID));
									if (voiddata.equals("Enable")) {
										Parameters.void_invoices_permission = true;
									} else {
										Parameters.void_invoices_permission = false;
									}
									System.out
											.println("void_invoices_permission permission is:"
													+ Parameters.void_invoices_permission);
									String transactions = cursoremployeepermission
											.getString(cursoremployeepermission
													.getColumnIndex(DatabaseForDemo.EMP_TRANSACTIONS));
									if (transactions.equals("Enable")) {
										Parameters.end_transaction_permission = true;
									} else {
										Parameters.end_transaction_permission = false;
									}
									System.out
											.println("end_transaction_permission permission is:"
													+ Parameters.end_transaction_permission);
									String holdprint = cursoremployeepermission
											.getString(cursoremployeepermission
													.getColumnIndex(DatabaseForDemo.EMP_HOLDPRINTS));
									if (holdprint.equals("Enable")) {
										Parameters.hold_print_permission = true;
									} else {
										Parameters.hold_print_permission = false;
									}
									System.out
											.println("hold_print_permission permission is:"
													+ Parameters.hold_print_permission);
									String credit = cursoremployeepermission
											.getString(cursoremployeepermission
													.getColumnIndex(DatabaseForDemo.EMP_CREDIT));
									if (credit.equals("Enable")) {
										Parameters.force_credit_cards_permission = true;
									} else {
										Parameters.force_credit_cards_permission = false;
									}
									System.out
											.println("force_credit_cards_permission permission is:"
													+ Parameters.force_credit_cards_permission);
									String endcash = cursoremployeepermission
											.getString(cursoremployeepermission
													.getColumnIndex(DatabaseForDemo.EMP_ENDCASH));
									if (endcash.equals("Enable")) {
										Parameters.end_cash_transaction_permission = true;
									} else {
										Parameters.end_cash_transaction_permission = false;
									}
									System.out
											.println("end_cash_transaction_permission permission is:"
													+ Parameters.end_cash_transaction_permission);

								} while (cursoremployeepermission.moveToNext());
							}
						}
						cursoremployeepermission.close();
						String parameterval = "?username=" + uName
								+ "&password=" + pwdmd5 + "&deviceid="
								+ Parameters.randomValue() + "&systemtime="
								+ Parameters.currentTime().replace(" ", "%20");
						ContentValues contentValues1 = new ContentValues();
						contentValues1.put(DatabaseForDemo.QUERY_TYPE,
								"userlogin");
						contentValues1.put(DatabaseForDemo.PENDING_USER_ID,
								Parameters.userid);
						contentValues1.put(DatabaseForDemo.PAGE_URL,
								"user-login.php");
						contentValues1.put(DatabaseForDemo.TABLE_NAME_PENDING,
								"");
						contentValues1.put(
								DatabaseForDemo.CURRENT_TIME_PENDING,
								Parameters.currentTime());
						contentValues1.put(DatabaseForDemo.PARAMETERS,
								parameterval);
						demodbG1.getWritableDatabase().insert(
								DatabaseForDemo.PENDING_QUERIES_TABLE, null,
								contentValues1);
						userName.setText("");
						passWord.setText("");

						Intent intent = new Intent(LoginHomeActivity.this,
								MenuActivity.class);
						startActivity(intent);
						permissions();

					} else {

						
							Toast.makeText(getApplicationContext(),
									"Enter correct Username and password", 1000)
									.show();
					}

				} else {
					if (bool)
					Toast.makeText(getApplicationContext(),
							"Enter username and password", 1000).show();
				}
				demodbG1.close();
			}*/
		}
	}

	@Override
	public boolean onKeyUp(int keyCode, KeyEvent event) {
		switch (keyCode) {
		case KeyEvent.KEYCODE_DPAD_CENTER:
			Toast.makeText(getApplicationContext(), "Ehhhhhhhhhhhhhhhhhh", 1000)
					.show();
			return true;
		case KeyEvent.KEYCODE_ENTER:
			loginMainMethod();
			return true;
		case KeyEvent.KEYCODE_J:
			return true;
		case KeyEvent.KEYCODE_K:
			return true;
		default:
			return super.onKeyUp(keyCode, event);
		}
	}

	void micellaneousTable() {
		
		Log.v("open", "sqlA1");
//		 sqliteDatabaseK1 = dbforloginlogoutWrite.
		String selectQuery = "SELECT  * FROM "
				+ DatabaseForDemo.MISCELLANEOUS_TABLE;
		Cursor mCursor = dbforloginlogoutWrite.rawQuery(selectQuery, null);
		//Parameters.mfindServer_url = true;
		if (mCursor != null) {
			Log.v("gfdkg", "super333....." + mCursor.getCount());
			String server_Url = "nnn";
			if (mCursor.getCount() < 1) {
				
				ContentValues contentValues = new ContentValues();
				contentValues.put(DatabaseForDemo.MISCEL_STORE, "Store1");
				contentValues.put(DatabaseForDemo.MISCEL_PAGEURL, Parameters.OriginalUrl);
				contentValues.put(DatabaseForDemo.MISCEL_UPDATE_LOCAL,
						Parameters.currentTime());
				contentValues.put(DatabaseForDemo.MISCEL_SERVER_UPDATE_LOCAL,
						Parameters.currentTime());
				Log.i("select", "" + contentValues);
				dbforloginlogoutWrite.insert(DatabaseForDemo.MISCELLANEOUS_TABLE,
						null, contentValues);
				contentValues.clear();
			} else {
				if (mCursor.moveToFirst()) {

					String url = mCursor.getString(mCursor
							.getColumnIndex(DatabaseForDemo.MISCEL_PAGEURL));
					if (url.length() > 3) {
						Parameters.OriginalUrl = url;
					}
				}
			}

		}
//		mCursor.close();
		//sqlA1.close();
//		sqliteDatabaseK1.close();
		Log.e("close","sqlA1");
	}
	void loginMainMethod() {

		InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
		imm.hideSoftInputFromWindow(passWord.getWindowToken(), 0);
		
		Log.e("open","sqlA1");
//		 dbinlogin = sqlA1.getReadableDatabase();
		String query = "select " + DatabaseForDemo.MISCEL_PAGEURL + " from "
				+ DatabaseForDemo.MISCELLANEOUS_TABLE;
		Cursor miscur = dbforloginlogoutRead.rawQuery(query, null);

		if (miscur != null) {
			if (miscur.getCount() > 0) {
				if (miscur.moveToFirst()) {
					do {
						if (miscur
								.isNull(miscur
										.getColumnIndex(DatabaseForDemo.MISCEL_PAGEURL))) {
							Parameters.OriginalUrl = "";
						} else {
							Parameters.OriginalUrl = miscur
									.getString(miscur
											.getColumnIndex(DatabaseForDemo.MISCEL_PAGEURL));
							//Parameters.OriginalUrl = urlval;
							System.out.println("url val is:" + Parameters.OriginalUrl);
						}
					} while (miscur.moveToNext());
				}
			}
		}
//		miscur.close();
//		dbinlogin.close();
		//sqlA1.close();
		Log.e("close","sqlA1");
		loginFunction();

	}
	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
		userName.setText("");
		passWord.setText("");
	}
	void printerDemoData(){
		
		Log.e("open","sqlA1");
//		 sqliteDatabasepri = dbforloginlogoutWrite.
		ContentValues contentValues = new ContentValues();
		contentValues.put(DatabaseForDemo.PRINTER_TEXT, "      AONEPOS" );
		contentValues.put(DatabaseForDemo.PRINTER_UNIT, "30" );
		contentValues.put(DatabaseForDemo.PRINTER_SPACING, "30");
		contentValues.put(DatabaseForDemo.PRINTER_FONT, "0" );
		contentValues
				.put(DatabaseForDemo.PRINTER_ALIGN, "0"  );
		contentValues
		.put(DatabaseForDemo.PRINTER_LANGUAGE, "0"  );
		contentValues
				.put(DatabaseForDemo.PRINTER_WSIZE, "1"   );
		contentValues
				.put(DatabaseForDemo.PRINTER_HSIZE, "1"  );
		contentValues.put(DatabaseForDemo.PRINTER_BOLD, "0" );
		contentValues.put(DatabaseForDemo.PRINTER_UNDERLINE, "0" );
		contentValues.put(DatabaseForDemo.PRINTER_XPOSITION, "0" );
		contentValues.put(DatabaseForDemo.PRINTER_TYPE, "EPSON" );
		contentValues.put(DatabaseForDemo.PRINTER_NAME, "TM-T82II");
		contentValues.put(DatabaseForDemo.PRINTER_IP, "192.168.1.168");
		contentValues.put(DatabaseForDemo.PRINTER_ID,"printer1" );
		dbforloginlogoutWrite.insert(DatabaseForDemo.PRINTER_TABLE, null,
				contentValues);
		contentValues.clear();
		
		
		contentValues.put(DatabaseForDemo.PRINTER_TEXT, "      AONEPOS" );
		contentValues.put(DatabaseForDemo.PRINTER_UNIT, "30" );
		contentValues.put(DatabaseForDemo.PRINTER_SPACING, "30");
		contentValues.put(DatabaseForDemo.PRINTER_FONT, "0" );
		contentValues
				.put(DatabaseForDemo.PRINTER_ALIGN, "0"  );
		contentValues
		.put(DatabaseForDemo.PRINTER_LANGUAGE, "0"  );
		contentValues
				.put(DatabaseForDemo.PRINTER_WSIZE, "1"   );
		contentValues
				.put(DatabaseForDemo.PRINTER_HSIZE, "1"  );
		contentValues.put(DatabaseForDemo.PRINTER_BOLD, "0" );
		contentValues.put(DatabaseForDemo.PRINTER_UNDERLINE, "0" );
		contentValues.put(DatabaseForDemo.PRINTER_XPOSITION, "0" );
		contentValues.put(DatabaseForDemo.PRINTER_TYPE, "STAR" );
		contentValues.put(DatabaseForDemo.PRINTER_NAME, "TSP100");
		contentValues.put(DatabaseForDemo.PRINTER_IP, "192.168.1.12");
		contentValues.put(DatabaseForDemo.PRINTER_ID,"printer2" );
		dbforloginlogoutWrite.insert(DatabaseForDemo.PRINTER_TABLE, null,
				contentValues);
		
		
//		sqliteDatabasepri.close();
		//sqlA1.close();
		Log.e("close","sqlA1");
	}
	void insertLoginTime(){
		
		Log.e("open","sqlA1");
//		 dbforloginlogout = dbforloginlogoutWrite.
		
		ContentValues values = new ContentValues();
		values.put(DatabaseForDemo.LOGIN_EMPLOYEE_NAME, uName);
		values.put(DatabaseForDemo.LOGIN_EMPLOYEE_ID, uName);
		values.put(DatabaseForDemo.LOGIN_TIME, Parameters.logintime);
		values.put(DatabaseForDemo.LOGOUT_TIME, "");
		values.put(DatabaseForDemo.DIFF_MINUTES, "00");
		values.put(DatabaseForDemo.DIFF_HOURS, "00");
		values.put(DatabaseForDemo.WAGES, "");
		values.put(DatabaseForDemo.CREATED_DATE, Parameters.currentTime());
		values.put(DatabaseForDemo.MODIFIED_DATE, Parameters.currentTime());
		values.put(DatabaseForDemo.MODIFIED_IN, "Local");
		values.put(DatabaseForDemo.SESSIONIDVAL, Parameters.sessionidforloginlogout);
		dbforloginlogoutWrite.insert(DatabaseForDemo.LOGIN_LOGOUT_TABLE, null, values);
		
//		dbforloginlogout.close();
		//sqlA1.close();
		Log.e("close","sqlA1");
	}
	void setEmployeePermissions(){
		
		Log.e("open","sqlA1");
		Cursor cursoremployeepermission = sqlA1
				.getReadableDatabase()
				.rawQuery(
						"select *from "
								+ DatabaseForDemo.EMP_PERMISSIONS_TABLE
								+ " where "
								+ DatabaseForDemo.EMPLOYEE_EMPLOYEE_ID
								+ "=\"" + uName + "\"", null);
		startManagingCursor(cursoremployeepermission);
		if (cursoremployeepermission != null) {
			if (cursoremployeepermission.getCount()>0) {
			if (cursoremployeepermission.moveToFirst()) {
				do {
					String inventory = cursoremployeepermission
							.getString(cursoremployeepermission
									.getColumnIndex(DatabaseForDemo.EMP_INVENTORY));
					if (inventory.equals("Enable")) {
						Parameters.inventory_permission = true;
					} else {
						Parameters.inventory_permission = false;
					}
					System.out
							.println("inventory permission is:"
									+ Parameters.inventory_permission);
					String customer = cursoremployeepermission
							.getString(cursoremployeepermission
									.getColumnIndex(DatabaseForDemo.EMP_CUSTOMERS));
					if (customer.equals("Enable")) {
						Parameters.customer_permission = true;
					} else {
						Parameters.customer_permission = false;
					}
					System.out
							.println("customer_permission permission is:"
									+ Parameters.customer_permission);
					String reports = cursoremployeepermission
							.getString(cursoremployeepermission
									.getColumnIndex(DatabaseForDemo.EMP_REPORTS));
					if (reports.equals("Enable")) {
						Parameters.reports_permission = true;
					} else {
						Parameters.reports_permission = false;
					}
					System.out.println("reports permission is:"
							+ Parameters.reports_permission);
					String discounts = cursoremployeepermission
							.getString(cursoremployeepermission
									.getColumnIndex(DatabaseForDemo.EMP_DISCOUNTS));
					if (discounts.equals("Enable")) {
						Parameters.invoice_discounts_permission = true;
					} else {
						Parameters.invoice_discounts_permission = false;
					}
					System.out
							.println("invoice_discounts_permission permission is:"
									+ Parameters.invoice_discounts_permission);
					String settings = cursoremployeepermission
							.getString(cursoremployeepermission
									.getColumnIndex(DatabaseForDemo.EMP_SETTINGS));
					if (settings.equals("Enable")) {
						Parameters.settings_permission = true;
					} else {
						Parameters.settings_permission = false;
					}
					System.out
							.println("settings_permission permission is:"
									+ Parameters.settings_permission);
					String pricechange = cursoremployeepermission
							.getString(cursoremployeepermission
									.getColumnIndex(DatabaseForDemo.EMP_PRICE));
					if (pricechange.equals("Enable")) {
						Parameters.invoice_price_change_permission = true;
					} else {
						Parameters.invoice_price_change_permission = false;
					}
					System.out
							.println("invoice_price_change_permission permission is:"
									+ Parameters.invoice_price_change_permission);
					String allowexit = cursoremployeepermission
							.getString(cursoremployeepermission
									.getColumnIndex(DatabaseForDemo.EMP_EXIT));
					if (allowexit.equals("Enable")) {
						Parameters.allow_exit_permission = true;
					} else {
						Parameters.allow_exit_permission = false;
					}
					System.out
							.println("allow_exit_permission permission is:"
									+ Parameters.allow_exit_permission);
					String payouts = cursoremployeepermission
							.getString(cursoremployeepermission
									.getColumnIndex(DatabaseForDemo.EMP_PAYOUTS));
					if (payouts.equals("Enable")) {
						Parameters.vendor_payouts_permission = true;
					} else {
						Parameters.vendor_payouts_permission = false;
					}
					System.out
							.println("vendor_payouts_permission permission is:"
									+ Parameters.vendor_payouts_permission);
					String delete = cursoremployeepermission
							.getString(cursoremployeepermission
									.getColumnIndex(DatabaseForDemo.EMP_DELETE));
					if (delete.equals("Enable")) {
						Parameters.delete_items_permission = true;
					} else {
						Parameters.delete_items_permission = false;
					}
					System.out
							.println("delete_items_permission permission is:"
									+ Parameters.delete_items_permission);
					String voiddata = cursoremployeepermission
							.getString(cursoremployeepermission
									.getColumnIndex(DatabaseForDemo.EMP_VOID));
					if (voiddata.equals("Enable")) {
						Parameters.void_invoices_permission = true;
					} else {
						Parameters.void_invoices_permission = false;
					}
					System.out
							.println("void_invoices_permission permission is:"
									+ Parameters.void_invoices_permission);
					String transactions = cursoremployeepermission
							.getString(cursoremployeepermission
									.getColumnIndex(DatabaseForDemo.EMP_TRANSACTIONS));
					if (transactions.equals("Enable")) {
						Parameters.end_transaction_permission = true;
					} else {
						Parameters.end_transaction_permission = false;
					}
					System.out
							.println("end_transaction_permission permission is:"
									+ Parameters.end_transaction_permission);
					String holdprint = cursoremployeepermission
							.getString(cursoremployeepermission
									.getColumnIndex(DatabaseForDemo.EMP_HOLDPRINTS));
					if (holdprint.equals("Enable")) {
						Parameters.hold_print_permission = true;
					} else {
						Parameters.hold_print_permission = false;
					}
					System.out
							.println("hold_print_permission permission is:"
									+ Parameters.hold_print_permission);
					String credit = cursoremployeepermission
							.getString(cursoremployeepermission
									.getColumnIndex(DatabaseForDemo.EMP_CREDIT));
					if (credit.equals("Enable")) {
						Parameters.force_credit_cards_permission = true;
					} else {
						Parameters.force_credit_cards_permission = false;
					}
					System.out
							.println("force_credit_cards_permission permission is:"
									+ Parameters.force_credit_cards_permission);
					String endcash = cursoremployeepermission
							.getString(cursoremployeepermission
									.getColumnIndex(DatabaseForDemo.EMP_ENDCASH));
					if (endcash.equals("Enable")) {
						Parameters.end_cash_transaction_permission = true;
					} else {
						Parameters.end_cash_transaction_permission = false;
					}
					System.out
							.println("end_cash_transaction_permission permission is:"
									+ Parameters.end_cash_transaction_permission);

				} while (cursoremployeepermission.moveToNext());
			}
			}else{
				adminPermissions(false);
			}
		}else{
			adminPermissions(false);
		}
//		cursoremployeepermission.close();
		//sqlA1.close();
		Log.e("close","sqlA1");
	}
	void saveinpendingQry(){
		
		Log.e("open","sqlA1");
		String parameterval = "?username=" + uName
				+ "&password=" + Parameters.MD5(pWord) + "&deviceid="
				+ Parameters.randomValue() + "&systemtime="
				+ Parameters.currentTime().replace(" ", "%20");
		ContentValues contentValues1 = new ContentValues();
		contentValues1.put(DatabaseForDemo.QUERY_TYPE,
				"userlogin");
		contentValues1.put(DatabaseForDemo.PENDING_USER_ID,
				Parameters.userid);
		contentValues1.put(DatabaseForDemo.PAGE_URL,
				"user-login.php");
		contentValues1.put(DatabaseForDemo.TABLE_NAME_PENDING,
				"");
		contentValues1.put(
				DatabaseForDemo.CURRENT_TIME_PENDING,
				Parameters.currentTime());
		contentValues1.put(DatabaseForDemo.PARAMETERS,
				parameterval);
		dbforloginlogoutWrite.insert(
				DatabaseForDemo.PENDING_QUERIES_TABLE, null,
				contentValues1);
		//sqlA1.close();
		Log.e("close","sqlA1");
	}
	void permissions(){
		if(Parameters.usertype.equals("admin")){
		Parameters.stores_permission=true;
		Parameters.profile_permission=true;
		Parameters.employee_permission=true;
		}else{
			Parameters.stores_permission=false;
			Parameters.profile_permission=false;
			Parameters.employee_permission=false;
		}
	}
	void adminPermissions(boolean value){
	
		Parameters.inventory_permission = value;
		
		Parameters.reports_permission = value;
		
		Parameters.settings_permission = value;
		
		Parameters.customer_permission = value;
		
		Parameters.allow_exit_permission = value;

		Parameters.delete_items_permission = value;
		
		Parameters.end_transaction_permission = value;
	
		Parameters.force_credit_cards_permission = value;
		
		Parameters.invoice_discounts_permission = value;
		
		Parameters.vendor_payouts_permission = value;
		
		Parameters.void_invoices_permission = value;
		
		Parameters.hold_print_permission = value;
		
		Parameters.end_cash_transaction_permission = value;
		
		Parameters.invoice_price_change_permission = value;
		
	}
}
